pub struct Files<'a> { /* private fields */ }async only.Expand description
Namespace handle for the Files API.
Implementations§
Source§impl<'a> Files<'a>
impl<'a> Files<'a>
Sourcepub async fn upload_path(&self, path: impl AsRef<Path>) -> Result<FileMetadata>
pub async fn upload_path(&self, path: impl AsRef<Path>) -> Result<FileMetadata>
Upload a file from disk.
Streams the file body through the request without buffering it in memory; suitable for large PDFs.
media_type defaults to application/octet-stream. The filename is
taken from the path’s file name component.
Sourcepub async fn upload_stream<R>(
&self,
reader: R,
filename: impl Into<String>,
media_type: impl Into<String>,
) -> Result<FileMetadata>
pub async fn upload_stream<R>( &self, reader: R, filename: impl Into<String>, media_type: impl Into<String>, ) -> Result<FileMetadata>
Upload from any AsyncRead source. The body is streamed; not
buffered. Retries are not applied to uploads – the source is
consumed.
Sourcepub async fn upload_bytes(
&self,
bytes: impl Into<Bytes>,
filename: impl Into<String>,
media_type: impl Into<String>,
) -> Result<FileMetadata>
pub async fn upload_bytes( &self, bytes: impl Into<Bytes>, filename: impl Into<String>, media_type: impl Into<String>, ) -> Result<FileMetadata>
Upload from a Bytes buffer (or anything that converts to Bytes).
Suitable for small payloads where streaming is overkill.
Sourcepub async fn get(&self, id: &str) -> Result<FileMetadata>
pub async fn get(&self, id: &str) -> Result<FileMetadata>
Fetch metadata for a single file by ID.
Sourcepub async fn list(
&self,
params: ListFilesParams,
) -> Result<Paginated<FileMetadata>>
pub async fn list( &self, params: ListFilesParams, ) -> Result<Paginated<FileMetadata>>
Fetch one page of file metadata.
Sourcepub async fn list_all(&self) -> Result<Vec<FileMetadata>>
pub async fn list_all(&self) -> Result<Vec<FileMetadata>>
Fetch every file’s metadata, transparently paging.
Sourcepub async fn delete(&self, id: &str) -> Result<FileDeleted>
pub async fn delete(&self, id: &str) -> Result<FileDeleted>
Delete a file by ID. Returns the deletion confirmation.
Sourcepub async fn download(&self, id: &str) -> Result<Bytes>
pub async fn download(&self, id: &str) -> Result<Bytes>
Download a file’s bytes into memory. Suitable for small files; for
streaming to disk or a network sink, use Self::download_to.
Sourcepub async fn download_to<W>(&self, id: &str, writer: &mut W) -> Result<u64>where
W: AsyncWrite + Unpin,
pub async fn download_to<W>(&self, id: &str, writer: &mut W) -> Result<u64>where
W: AsyncWrite + Unpin,
Stream a file’s bytes into any AsyncWrite sink. Returns the
total number of bytes written.
Auto Trait Implementations§
impl<'a> Freeze for Files<'a>
impl<'a> !RefUnwindSafe for Files<'a>
impl<'a> Send for Files<'a>
impl<'a> Sync for Files<'a>
impl<'a> Unpin for Files<'a>
impl<'a> UnsafeUnpin for Files<'a>
impl<'a> !UnwindSafe for Files<'a>
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
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more