pub enum FileSource {
Bytes {
filename: String,
bytes: Vec<u8>,
content_type: String,
},
Path(PathBuf),
Stream {
filename: String,
reader: Pin<Box<dyn AsyncRead + Send>>,
content_type: String,
},
}Expand description
A source for file data that will be uploaded.
Construct with FileSource::bytes, FileSource::path, or
FileSource::stream, or convert from PathBuf/std::path::Path via the
From impls.
The API currently accepts text/plain, application/pdf, and
application/json; other MIME types may be rejected by the server.
Variants§
Bytes
Raw bytes with explicit filename and content type.
Fields
Path(PathBuf)
A filesystem path. Resolved at upload time.
Stream
A streaming reader — fully buffered into memory before uploading.
Implementations§
Source§impl FileSource
impl FileSource
Sourcepub fn bytes(
filename: impl Into<String>,
data: impl Into<Vec<u8>>,
content_type: impl Into<String>,
) -> Self
pub fn bytes( filename: impl Into<String>, data: impl Into<Vec<u8>>, content_type: impl Into<String>, ) -> Self
Create a Bytes variant from explicit parts.
The API currently accepts text/plain, application/pdf, and
application/json; other MIME types may be rejected by the server.
Sourcepub fn stream(
filename: impl Into<String>,
reader: impl AsyncRead + Send + 'static,
content_type: impl Into<String>,
) -> Self
pub fn stream( filename: impl Into<String>, reader: impl AsyncRead + Send + 'static, content_type: impl Into<String>, ) -> Self
Create a Stream variant from an AsyncRead source.
The reader is fully consumed with tokio::io::AsyncReadExt::read_to_end
and buffered into a Vec<u8> before the upload begins. This is not
true streaming — the entire payload resides in memory during the request.
For files on disk, prefer FileSource::path which streams from the
filesystem without buffering.
The API currently accepts text/plain, application/pdf, and
application/json; other MIME types may be rejected by the server.
§Examples
use honcho_ai::FileSource;
let cursor = std::io::Cursor::new(b"hello".to_vec());
let src = FileSource::stream("out.txt", cursor, "text/plain");