pub struct Bucket {
pub host: Url,
pub name: String,
pub region: Region,
pub credentials: Credentials,
/* private fields */
}Expand description
S3 Bucket operations, your main entrypoint
Fields§
§host: Url§name: String§region: Region§credentials: CredentialsImplementations§
Source§impl Bucket
impl Bucket
pub fn new( host: Url, name: String, region: Region, credentials: Credentials, options: Option<BucketOptions>, ) -> Result<Self, S3Error>
pub fn try_from_env() -> Result<Self, S3Error>
Sourcepub async fn head<S: AsRef<str>>(
&self,
path: S,
) -> Result<HeadObjectResult, S3Error>
pub async fn head<S: AsRef<str>>( &self, path: S, ) -> Result<HeadObjectResult, S3Error>
HEAD information for an object
Sourcepub async fn get<P>(&self, path: P) -> Result<S3Response, S3Error>
pub async fn get<P>(&self, path: P) -> Result<S3Response, S3Error>
GET an object
pub async fn get_range<S: AsRef<str>>( &self, path: S, start: u64, end: Option<u64>, ) -> Result<S3Response, S3Error>
Sourcepub async fn delete<S: AsRef<str>>(
&self,
path: S,
) -> Result<S3Response, S3Error>
pub async fn delete<S: AsRef<str>>( &self, path: S, ) -> Result<S3Response, S3Error>
DELETE an object
Sourcepub async fn put<S: AsRef<str>>(
&self,
path: S,
content: &[u8],
) -> Result<S3Response, S3Error>
pub async fn put<S: AsRef<str>>( &self, path: S, content: &[u8], ) -> Result<S3Response, S3Error>
PUT an object
Sourcepub async fn put_with_content_type<S: AsRef<str>>(
&self,
path: S,
content: &[u8],
content_type: &str,
) -> Result<S3Response, S3Error>
pub async fn put_with_content_type<S: AsRef<str>>( &self, path: S, content: &[u8], content_type: &str, ) -> Result<S3Response, S3Error>
PUT an object with a specific content type
Sourcepub async fn put_with<S: AsRef<str>>(
&self,
path: S,
content: &[u8],
extra_headers: HeaderMap,
) -> Result<S3Response, S3Error>
pub async fn put_with<S: AsRef<str>>( &self, path: S, content: &[u8], extra_headers: HeaderMap, ) -> Result<S3Response, S3Error>
PUT an object with specific headers.
headers accepts additional headers to include in the request. Required headers for the
request (i.e. Authorization, Content-Length) don’t need to be included, as they are
still handled automatically.
§Examples
let bucket = Bucket::try_from_env().await?;
let mut headers = HeaderMap::new();
let content = b"world";
// Denote that this a text file.
headers.insert("Content-Type", "text/plain");
// Tell S3 what the caching behavior this object should respond to clients with.
headers.insert("Cache-Control", "public, max-age=3600");
bucket.put_with("hello.txt", content, headers).await?;Sourcepub async fn put_stream<R>(
&self,
reader: &mut R,
path: String,
) -> Result<PutStreamResponse, S3Error>
pub async fn put_stream<R>( &self, reader: &mut R, path: String, ) -> Result<PutStreamResponse, S3Error>
Streaming object upload from any reader that implements AsyncRead
Sourcepub async fn put_stream_with_content_type<R>(
&self,
reader: &mut R,
path: String,
content_type: String,
) -> Result<PutStreamResponse, S3Error>
pub async fn put_stream_with_content_type<R>( &self, reader: &mut R, path: String, content_type: String, ) -> Result<PutStreamResponse, S3Error>
Streaming object upload from any reader that implements AsyncRead
Sourcepub async fn put_stream_with<R>(
&self,
reader: &mut R,
path: String,
extra_headers: HeaderMap,
) -> Result<PutStreamResponse, S3Error>
pub async fn put_stream_with<R>( &self, reader: &mut R, path: String, extra_headers: HeaderMap, ) -> Result<PutStreamResponse, S3Error>
Streaming object upload from any reader that implements AsyncRead.
headers accepts additional headers to include in the request. Required headers for the
request (i.e. Authorization, Content-Length) don’t need to be included, as they are
still handled automatically.
Sourcepub async fn list(
&self,
prefix: &str,
delimiter: Option<&str>,
) -> Result<Vec<ListBucketResult>, S3Error>
pub async fn list( &self, prefix: &str, delimiter: Option<&str>, ) -> Result<Vec<ListBucketResult>, S3Error>
List bucket contents
Sourcepub async fn copy_internal<F, T>(
&self,
from: F,
to: T,
) -> Result<S3StatusCode, S3Error>
pub async fn copy_internal<F, T>( &self, from: F, to: T, ) -> Result<S3StatusCode, S3Error>
S3 internal copy an object from one place to another inside the same bucket
Sourcepub async fn copy_internal_with<F, T>(
&self,
from: F,
to: T,
extra_headers: HeaderMap,
) -> Result<S3StatusCode, S3Error>
pub async fn copy_internal_with<F, T>( &self, from: F, to: T, extra_headers: HeaderMap, ) -> Result<S3StatusCode, S3Error>
S3 internal copy an object from one place to another inside the same bucket.
headers accepts additional headers to include in the request. Required headers for the
request (i.e. Authorization, Content-Length) don’t need to be included, as they are
still handled automatically.
§Examples
This example shows how to modify the metadata of an existing object in S3.
let bucket = Bucket::try_from_env().await?;
let mut headers = HeaderMap::new();
// `x-amz-metadata-directive` tells S3 what to do with the existing object metadata.
headers.insert("x-amz-metadata-directive", "REPLACE");
headers.insert("Content-Type", "image/jpeg");
headers.insert("Cache-Control", "public, max-age=86400");
bucket.copy_internal_with("cat.jpg", "cat.jpg", headers).await?;