[][src]Struct cloud_storage_rs::Bucket

pub struct Bucket { /* fields omitted */ }

Represents a Bucket in Google Cloud Storage that can be used to upload, download or move files. Internally, the files in the bucket live in a flat namespace, that is, the slashes that indicate folders are simply part of the filename. This means that renaming a file and moving it to a different directory are the same operation.

Methods

impl Bucket[src]

pub fn existing(name: &str) -> Self[src]

Returns a Bucket struct with the corresponding name. If the bucket does not exist, an attempt to store or retrieve files will always fail.

let bucket = Bucket::existing("my-companies-production-bucket");

pub fn create(name: &str) -> Result<Self, Error>[src]

Creates a new Bucket resource on Goolge's server, then returns a struct representing this Bucket.

let bucket = Bucket::create("my-companies-staging-bucket").unwrap();

pub fn upload(
    &self,
    file: &[u8],
    filename: &str,
    mime_type: &str
) -> Result<(), Error>
[src]

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.

let bucket = Bucket::existing("cat-photos");
let file: Vec<u8> = read_cute_cat("cat.png");
bucket.upload(&file, "recently read cat.png", "image/png").expect("cat not uploaded");

pub fn update(&self, old_name: &str, new_name: &str) -> Result<(), Error>[src]

Allows renaming a file. Note that since a files name is its full path, you can use the renaming capacities to move files as well.

let bucket = Bucket::existing("cat-photos");
bucket.update("recently read cat.png", "cuties/old cat.png").expect("cat not moved");

pub fn delete(&self, name: &str) -> Result<(), Error>[src]

Removes a file from the Bucket. Depending on your content retention policy, this may very well be permanent!

let bucket = Bucket::existing("cat-photos");
bucket.delete("dog.jpg").expect("wrong animal not removed");

pub fn download_url(&self, file_path: &str, duration: u32) -> String[src]

Generates a signed url that is valid for duration seconds, that lets anyone read the file without further authentication. Note that this function returns a String, so generating the signed url will never fail. If the file does not exist, or the service account has no access to the file, then the signed url will result in a 404 or a 401.

let bucket = Bucket::existing("cat-photos");
let url = bucket.download_url("cuties/old cat.png");
// now we can download the file as desired, for example:
let file = reqwest::blocking::get(&url).unwrap()
    .bytes().unwrap();
// we now have the file again

Auto Trait Implementations

impl Send for Bucket

impl Sync for Bucket

impl Unpin for Bucket

impl UnwindSafe for Bucket

impl RefUnwindSafe for Bucket

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Err = <U as TryFrom<T>>::Err