pub struct File {
pub name: String,
pub mime_type: Mime,
pub data: FileData,
pub size: u64,
pub hash: Option<String>,
}
Expand description
Represents a file that can be uploaded to the Anthropic API
Fields§
§name: String
File name
mime_type: Mime
MIME type
data: FileData
File data
size: u64
File size in bytes
hash: Option<String>
Optional file hash for integrity verification
Implementations§
Source§impl File
impl File
Sourcepub fn from_bytes(
name: impl Into<String>,
bytes: impl Into<Bytes>,
mime_type: Option<Mime>,
) -> Result<Self, FileError>
pub fn from_bytes( name: impl Into<String>, bytes: impl Into<Bytes>, mime_type: Option<Mime>, ) -> Result<Self, FileError>
Create a new file from bytes
Sourcepub fn from_path(path: impl AsRef<Path>) -> Result<Self, FileError>
pub fn from_path(path: impl AsRef<Path>) -> Result<Self, FileError>
Create a new file from a file path
Sourcepub fn from_base64(
name: impl Into<String>,
base64_data: impl Into<String>,
mime_type: Option<Mime>,
) -> Result<Self, FileError>
pub fn from_base64( name: impl Into<String>, base64_data: impl Into<String>, mime_type: Option<Mime>, ) -> Result<Self, FileError>
Create a new file from base64 data
Sourcepub fn from_std_file(
std_file: StdFile,
name: impl Into<String>,
mime_type: Option<Mime>,
) -> Result<Self, FileError>
pub fn from_std_file( std_file: StdFile, name: impl Into<String>, mime_type: Option<Mime>, ) -> Result<Self, FileError>
Create a file from a standard library File
Sourcepub fn validate(&self, constraints: &FileConstraints) -> Result<(), FileError>
pub fn validate(&self, constraints: &FileConstraints) -> Result<(), FileError>
Validate the file against constraints
Sourcepub async fn calculate_hash(&mut self) -> Result<String, FileError>
pub async fn calculate_hash(&mut self) -> Result<String, FileError>
Calculate and set the file hash
Sourcepub async fn verify_hash(&self, expected_hash: &str) -> Result<bool, FileError>
pub async fn verify_hash(&self, expected_hash: &str) -> Result<bool, FileError>
Verify the file hash
Sourcepub fn is_application(&self) -> bool
pub fn is_application(&self) -> bool
Check if this is an application file (e.g., PDF, document)
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for File
impl RefUnwindSafe for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnwindSafe for File
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.