Struct cloud_storage::sync::ObjectClient
source · [−]pub struct ObjectClient<'a>(_);
Expand description
Operations on Object
s.
Implementations
sourceimpl<'a> ObjectClient<'a>
impl<'a> ObjectClient<'a>
sourcepub fn create(
&self,
bucket: &str,
file: Vec<u8>,
filename: &str,
mime_type: &str
) -> Result<Object>
pub fn create(
&self,
bucket: &str,
file: Vec<u8>,
filename: &str,
mime_type: &str
) -> Result<Object>
Create a new object. Upload a file as that is loaded in memory to google cloud storage, where it will be interpreted according to the mime type you specified.
Example
use cloud_storage::sync::Client;
use cloud_storage::Object;
let file: Vec<u8> = read_cute_cat("cat.png");
let client = Client::new()?;
client.object().create("cat-photos", file, "recently read cat.png", "image/png")?;
sourcepub fn create_streamed<R>(
&self,
bucket: &str,
file: R,
length: impl Into<Option<u64>>,
filename: &str,
mime_type: &str
) -> Result<Object> where
R: Read + Send + Sync + Unpin + 'static,
pub fn create_streamed<R>(
&self,
bucket: &str,
file: R,
length: impl Into<Option<u64>>,
filename: &str,
mime_type: &str
) -> Result<Object> where
R: Read + Send + Sync + Unpin + 'static,
Create a new object. This works in the same way as ObjectClient::create
, except it does not need
to load the entire file in ram.
sourcepub fn list(
&self,
bucket: &'a str,
list_request: ListRequest
) -> Result<Vec<ObjectList>>
pub fn list(
&self,
bucket: &'a str,
list_request: ListRequest
) -> Result<Vec<ObjectList>>
Obtain a list of objects within this Bucket.
Example
use cloud_storage::sync::Client;
use cloud_storage::{Object, ListRequest};
let client = Client::new()?;
let all_objects = client.object().list("my_bucket", ListRequest::default())?;
sourcepub fn read(&self, bucket: &str, file_name: &str) -> Result<Object>
pub fn read(&self, bucket: &str, file_name: &str) -> Result<Object>
Obtains a single object with the specified name in the specified bucket.
Example
use cloud_storage::sync::Client;
use cloud_storage::Object;
let client = Client::new()?;
let object = client.object().read("my_bucket", "path/to/my/file.png")?;
sourcepub fn download(&self, bucket: &str, file_name: &str) -> Result<Vec<u8>>
pub fn download(&self, bucket: &str, file_name: &str) -> Result<Vec<u8>>
Download the content of the object with the specified name in the specified bucket.
Example
use cloud_storage::sync::Client;
use cloud_storage::Object;
let client = Client::new()?;
let bytes = client.object().download("my_bucket", "path/to/my/file.png")?;
sourcepub fn update(&self, object: &Object) -> Result<Object>
pub fn update(&self, object: &Object) -> Result<Object>
Obtains a single object with the specified name in the specified bucket.
Example
use cloud_storage::sync::Client;
use cloud_storage::Object;
let client = Client::new()?;
let mut object = client.object().read("my_bucket", "path/to/my/file.png")?;
object.content_type = Some("application/xml".to_string());
client.object().update(&object)?;
sourcepub fn delete(&self, bucket: &str, file_name: &str) -> Result<()>
pub fn delete(&self, bucket: &str, file_name: &str) -> Result<()>
Deletes a single object with the specified name in the specified bucket.
Example
use cloud_storage::sync::Client;
use cloud_storage::Object;
let client = Client::new()?;
client.object().delete("my_bucket", "path/to/my/file.png")?;
sourcepub fn compose(
&self,
bucket: &str,
req: &ComposeRequest,
destination_object: &str
) -> Result<Object>
pub fn compose(
&self,
bucket: &str,
req: &ComposeRequest,
destination_object: &str
) -> Result<Object>
Obtains a single object with the specified name in the specified bucket.
Example
use cloud_storage::sync::Client;
use cloud_storage::object::{Object, ComposeRequest, SourceObject};
let client = Client::new()?;
let obj1 = client.object().read("my_bucket", "file1")?;
let obj2 = client.object().read("my_bucket", "file2")?;
let compose_request = ComposeRequest {
kind: "storage#composeRequest".to_string(),
source_objects: vec![
SourceObject {
name: obj1.name.clone(),
generation: None,
object_preconditions: None,
},
SourceObject {
name: obj2.name.clone(),
generation: None,
object_preconditions: None,
},
],
destination: None,
};
let obj3 = client.object().compose("my_bucket", &compose_request, "test-concatted-file")?;
// obj3 is now a file with the content of obj1 and obj2 concatted together.
sourcepub fn copy(
&self,
object: &Object,
destination_bucket: &str,
path: &str
) -> Result<Object>
pub fn copy(
&self,
object: &Object,
destination_bucket: &str,
path: &str
) -> Result<Object>
Copy this object to the target bucket and path
Example
use cloud_storage::sync::Client;
use cloud_storage::object::{Object, ComposeRequest};
let client = Client::new()?;
let obj1 = client.object().read("my_bucket", "file1")?;
let obj2 = client.object().copy(&obj1, "my_other_bucket", "file2")?;
// obj2 is now a copy of obj1.
sourcepub fn rewrite(
&self,
object: &Object,
destination_bucket: &str,
path: &str
) -> Result<Object>
pub fn rewrite(
&self,
object: &Object,
destination_bucket: &str,
path: &str
) -> Result<Object>
Moves a file from the current location to the target bucket and path.
Limitations
This function does not yet support rewriting objects to another
- Geographical Location,
- Encryption,
- Storage class. These limitations mean that for now, the rewrite and the copy methods do the same thing.
Example
use cloud_storage::sync::Client;
use cloud_storage::object::Object;
let client = Client::new()?;
let obj1 = client.object().read("my_bucket", "file1")?;
let obj2 = client.object().rewrite(&obj1, "my_other_bucket", "file2")?;
// obj2 is now a copy of obj1.
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for ObjectClient<'a>
impl<'a> Send for ObjectClient<'a>
impl<'a> Sync for ObjectClient<'a>
impl<'a> Unpin for ObjectClient<'a>
impl<'a> !UnwindSafe for ObjectClient<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more