#[non_exhaustive]pub enum FileSource {
#[non_exhaustive] Bytes {
filename: String,
bytes: Vec<u8>,
content_type: String,
},
#[non_exhaustive] Path(PathBuf),
#[non_exhaustive] 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.
This enum is #[non_exhaustive]: new variants may be added in future
versions without a breaking change, and each data-carrying variant is
likewise #[non_exhaustive] so that new fields can be added to it
non-breakingly. Out-of-crate code must construct values through the
provided constructors (FileSource::bytes, FileSource::path,
FileSource::stream, or the From impls) rather than variant literals,
and cannot exhaustively match on the variants or their fields.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
#[non_exhaustive]Bytes
Raw bytes with explicit filename and content type.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]Path(PathBuf)
A filesystem path. Resolved at upload time.
#[non_exhaustive]Stream
A streaming reader — fully buffered into memory before uploading.
Fields
This variant is marked as non-exhaustive
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.
data accepts anything convertible into Vec<u8> (e.g. Vec<u8>,
&[u8], &str) and is stored as a Vec<u8>.
The content type is validated when the upload is sent (during multipart form construction), not here, to keep this constructor infallible.
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 memory 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.
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");