pub struct StorageClient { /* private fields */ }

Implementations§

source§

impl StorageClient

source

pub async fn delete_bucket( &self, req: &DeleteBucketRequest ) -> Result<(), Error>

Deletes the bucket. https://cloud.google.com/storage/docs/json_api/v1/buckets/delete

use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::delete::DeleteBucketRequest;

async fn run(client:Client) {
    let result = client.delete_bucket(&DeleteBucketRequest {
        bucket: "bucket".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn insert_bucket( &self, req: &InsertBucketRequest ) -> Result<Bucket, Error>

Inserts the bucket. https://cloud.google.com/storage/docs/json_api/v1/buckets/insert

use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::insert::{BucketCreationConfig, InsertBucketParam, InsertBucketRequest};

async fn run(client:Client) {
    let result = client.insert_bucket(&InsertBucketRequest {
        name: "bucket".to_string(),
        param: InsertBucketParam {
            project: "project_id".to_string(),
            ..Default::default()
        },
        ..Default::default()
    }).await;
}
source

pub async fn get_bucket(&self, req: &GetBucketRequest) -> Result<Bucket, Error>

Gets the bucket. https://cloud.google.com/storage/docs/json_api/v1/buckets/get

use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::get::GetBucketRequest;

async fn run(client:Client) {
    let result = client.get_bucket(&GetBucketRequest {
        bucket: "bucket".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn patch_bucket( &self, req: &PatchBucketRequest ) -> Result<Bucket, Error>

Patches the bucket. https://cloud.google.com/storage/docs/json_api/v1/buckets/patch

use google_cloud_storage::client::Client;
use google_cloud_storage::client::ClientConfig;
use google_cloud_storage::http::buckets::patch::{BucketPatchConfig, PatchBucketRequest};

async fn run(config: ClientConfig) {
    let mut client = Client::new(config);

    let result = client.patch_bucket(&PatchBucketRequest {
        bucket: "bucket".to_string(),
        metadata: Some(BucketPatchConfig {
            ..Default::default()
        }),
        ..Default::default()
    }).await;
}
source

pub async fn list_buckets( &self, req: &ListBucketsRequest ) -> Result<ListBucketsResponse, Error>

Lists the bucket. https://cloud.google.com/storage/docs/json_api/v1/buckets/list

use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::list::ListBucketsRequest;

async fn run(client:Client) {
    let result = client.list_buckets(&ListBucketsRequest{
        project: "project_id".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn set_iam_policy( &self, req: &SetIamPolicyRequest ) -> Result<Policy, Error>

Sets the iam policy. https://cloud.google.com/storage/docs/json_api/v1/buckets/setIamPolicy

use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::{Binding, Policy};
use google_cloud_storage::http::buckets::set_iam_policy::SetIamPolicyRequest;

async fn run(client:Client) {
    let result = client.set_iam_policy(&SetIamPolicyRequest{
        resource: "bucket".to_string(),
        policy: Policy {
            bindings: vec![Binding {
                role: "roles/storage.objectViewer".to_string(),
                members: vec!["allAuthenticatedUsers".to_string()],
                condition: None,
            }],
            ..Default::default()
        },
        ..Default::default()
    }).await;
}
source

pub async fn get_iam_policy( &self, req: &GetIamPolicyRequest ) -> Result<Policy, Error>

Gets the iam policy. https://cloud.google.com/storage/docs/json_api/v1/buckets/getIamPolicy

use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::get_iam_policy::GetIamPolicyRequest;
use google_cloud_storage::http::buckets::list::ListBucketsRequest;

async fn run(client:Client) {
    let result = client.get_iam_policy(&GetIamPolicyRequest{
        resource: "bucket".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn test_iam_permissions( &self, req: &TestIamPermissionsRequest ) -> Result<TestIamPermissionsResponse, Error>

Tests the iam permissions. https://cloud.google.com/storage/docs/json_api/v1/buckets/testIamPermissions

use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::test_iam_permissions::TestIamPermissionsRequest;

async fn run(client:Client) {
    let result = client.test_iam_permissions(&TestIamPermissionsRequest{
        resource: "bucket".to_string(),
        permissions: vec!["storage.buckets.get".to_string()],
    }).await;
}
source

pub async fn list_default_object_access_controls( &self, req: &ListDefaultObjectAccessControlsRequest ) -> Result<ListDefaultObjectAccessControlsResponse, Error>

Lists the default object ACL. https://cloud.google.com/storage/docs/json_api/v1/defaultObjectAccessControls/list

use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::test_iam_permissions::TestIamPermissionsRequest;
use google_cloud_storage::http::default_object_access_controls::list::ListDefaultObjectAccessControlsRequest;

async fn run(client:Client) {
    let result = client.list_default_object_access_controls(&ListDefaultObjectAccessControlsRequest{
        bucket: "bucket".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn get_default_object_access_control( &self, req: &GetDefaultObjectAccessControlRequest ) -> Result<ObjectAccessControl, Error>

Gets the default object ACL. https://cloud.google.com/storage/docs/json_api/v1/defaultObjectAccessControls/get

use google_cloud_storage::client::Client;
use google_cloud_storage::http::default_object_access_controls::get::GetDefaultObjectAccessControlRequest;

async fn run(client:Client) {
    let result = client.get_default_object_access_control(&GetDefaultObjectAccessControlRequest{
        bucket: "bucket".to_string(),
        entity: "allAuthenticatedUsers".to_string(),
    }).await;
}
source

pub async fn insert_default_object_access_control( &self, req: &InsertDefaultObjectAccessControlRequest ) -> Result<ObjectAccessControl, Error>

Inserts the default object ACL. https://cloud.google.com/storage/docs/json_api/v1/defaultObjectAccessControls/insert

use google_cloud_storage::client::Client;
use google_cloud_storage::http::default_object_access_controls::insert::InsertDefaultObjectAccessControlRequest;
use google_cloud_storage::http::object_access_controls::insert::ObjectAccessControlCreationConfig;
use google_cloud_storage::http::object_access_controls::ObjectACLRole;

async fn run(client:Client) {
    let result = client.insert_default_object_access_control(&InsertDefaultObjectAccessControlRequest{
        bucket: "bucket".to_string(),
        object_access_control: ObjectAccessControlCreationConfig {
            entity: "allAuthenticatedUsers".to_string(),
            role: ObjectACLRole::READER
        } ,
    }).await;
}
source

pub async fn patch_default_object_access_control( &self, req: &PatchDefaultObjectAccessControlRequest ) -> Result<ObjectAccessControl, Error>

Patches the default object ACL. https://cloud.google.com/storage/docs/json_api/v1/defaultObjectAccessControls/patch

use google_cloud_storage::client::Client;
use google_cloud_storage::http::default_object_access_controls::patch::PatchDefaultObjectAccessControlRequest;
use google_cloud_storage::http::object_access_controls::insert::ObjectAccessControlCreationConfig;
use google_cloud_storage::http::object_access_controls::{ObjectAccessControl, ObjectACLRole};
use google_cloud_storage::http::object_access_controls::patch::PatchObjectAccessControlRequest;

async fn run(client:Client) {
    let result = client.patch_default_object_access_control(&PatchDefaultObjectAccessControlRequest{
        bucket: "bucket".to_string(),
        entity: "allAuthenticatedUsers".to_string(),
        object_access_control: ObjectAccessControl {
            role: ObjectACLRole::READER,
            ..Default::default()
        },
    }).await;
}
source

pub async fn delete_default_object_access_control( &self, req: &DeleteDefaultObjectAccessControlRequest ) -> Result<(), Error>

Deletes the default object ACL. https://cloud.google.com/storage/docs/json_api/v1/defaultObjectAccessControls/delete

use google_cloud_storage::client::Client;
use google_cloud_storage::http::default_object_access_controls::delete::DeleteDefaultObjectAccessControlRequest;

async fn run(client:Client) {
    let result = client.delete_default_object_access_control(&DeleteDefaultObjectAccessControlRequest{
        bucket: "bucket".to_string(),
        entity: "allAuthenticatedUsers".to_string(),
    }).await;
}
source

pub async fn list_bucket_access_controls( &self, req: &ListBucketAccessControlsRequest ) -> Result<ListBucketAccessControlsResponse, Error>

Lists the bucket ACL. https://cloud.google.com/storage/docs/json_api/v1/bucketAccessControls/list

use google_cloud_storage::client::Client;
use google_cloud_storage::http::bucket_access_controls::list::ListBucketAccessControlsRequest;

async fn run(client:Client) {
    let result = client.list_bucket_access_controls(&ListBucketAccessControlsRequest{
        bucket: "bucket".to_string(),
    }).await;
}
source

pub async fn get_bucket_access_control( &self, req: &GetBucketAccessControlRequest ) -> Result<BucketAccessControl, Error>

Gets the bucket ACL. https://cloud.google.com/storage/docs/json_api/v1/bucketAccessControls/get

use google_cloud_storage::client::Client;
use google_cloud_storage::http::bucket_access_controls::get::GetBucketAccessControlRequest;

async fn run(client:Client) {
    let result = client.get_bucket_access_control(&GetBucketAccessControlRequest{
        bucket: "bucket".to_string(),
        entity: "allAuthenticatedUsers".to_string(),
    }).await;
}
source

pub async fn insert_bucket_access_control( &self, req: &InsertBucketAccessControlRequest ) -> Result<BucketAccessControl, Error>

Inserts the bucket ACL. https://cloud.google.com/storage/docs/json_api/v1/bucketAccessControls/insert

use google_cloud_storage::client::Client;
use google_cloud_storage::http::bucket_access_controls::BucketACLRole;
use google_cloud_storage::http::bucket_access_controls::insert::{BucketAccessControlCreationConfig, InsertBucketAccessControlRequest};

async fn run(client:Client) {
    let result = client.insert_bucket_access_control(&InsertBucketAccessControlRequest{
        bucket: "bucket".to_string(),
        acl: BucketAccessControlCreationConfig {
            entity: "allAuthenticatedUsers".to_string(),
            role: BucketACLRole::READER
        }
    }).await;
}
source

pub async fn patch_bucket_access_control( &self, req: &PatchBucketAccessControlRequest ) -> Result<BucketAccessControl, Error>

Patches the bucket ACL. https://cloud.google.com/storage/docs/json_api/v1/bucketAccessControls/patch

use google_cloud_storage::client::Client;
use google_cloud_storage::http::bucket_access_controls::BucketAccessControl;
use google_cloud_storage::http::bucket_access_controls::BucketACLRole;
use google_cloud_storage::http::bucket_access_controls::patch::PatchBucketAccessControlRequest;

async fn run(client:Client) {
    let result = client.patch_bucket_access_control(&PatchBucketAccessControlRequest{
        bucket: "bucket".to_string(),
        entity: "allAuthenticatedUsers".to_string(),
        acl: BucketAccessControl {
            role: BucketACLRole::READER,
            ..Default::default()
        }
    }).await;
}
source

pub async fn delete_bucket_access_control( &self, req: &DeleteBucketAccessControlRequest ) -> Result<(), Error>

Deletes the bucket ACL.

use google_cloud_storage::client::Client;
use google_cloud_storage::http::bucket_access_controls::BucketAccessControl;
use google_cloud_storage::http::bucket_access_controls::delete::DeleteBucketAccessControlRequest;

async fn run(client:Client) {
    let result = client.delete_bucket_access_control(&DeleteBucketAccessControlRequest{
        bucket: "bucket".to_string(),
        entity: "allAuthenticatedUsers".to_string(),
    }).await;
}
source

pub async fn list_object_access_controls( &self, req: &ListObjectAccessControlsRequest ) -> Result<ListBucketAccessControlsResponse, Error>

Lists the object ACL. https://cloud.google.com/storage/docs/json_api/v1/objectAccessControls/list

use google_cloud_storage::client::Client;
use google_cloud_storage::http::object_access_controls::list::ListObjectAccessControlsRequest;

async fn run(client:Client) {
    let result = client.list_object_access_controls(&ListObjectAccessControlsRequest{
        bucket: "bucket".to_string(),
        object: "filename".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn get_object_access_control( &self, req: &GetObjectAccessControlRequest ) -> Result<ObjectAccessControl, Error>

Gets the object ACL. https://cloud.google.com/storage/docs/json_api/v1/objectAccessControls/get

use google_cloud_storage::client::Client;
use google_cloud_storage::http::object_access_controls::get::GetObjectAccessControlRequest;


async fn run(client:Client) {

    let result = client.get_object_access_control(&GetObjectAccessControlRequest{
        bucket: "bucket".to_string(),
        object: "filename".to_string(),
        entity: "allAuthenticatedUsers".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn insert_object_access_control( &self, req: &InsertObjectAccessControlRequest ) -> Result<ObjectAccessControl, Error>

Inserts the object ACL. https://cloud.google.com/storage/docs/json_api/v1/objectAccessControls/insert

use google_cloud_storage::client::Client;
use google_cloud_storage::http::object_access_controls::insert::{InsertObjectAccessControlRequest, ObjectAccessControlCreationConfig};
use google_cloud_storage::http::object_access_controls::ObjectACLRole;


async fn run(client:Client) {

    let result = client.insert_object_access_control(&InsertObjectAccessControlRequest{
        bucket: "bucket".to_string(),
        object: "filename".to_string(),
        acl: ObjectAccessControlCreationConfig {
            entity: "allAuthenticatedUsers".to_string(),
            role: ObjectACLRole::READER
        },
        ..Default::default()
    }).await;
}
source

pub async fn patch_object_access_control( &self, req: &PatchObjectAccessControlRequest ) -> Result<ObjectAccessControl, Error>

Patches the bucket ACL. https://cloud.google.com/storage/docs/json_api/v1/objectAccessControls/patch

use google_cloud_storage::client::Client;
use google_cloud_storage::http::object_access_controls::{ObjectAccessControl, ObjectACLRole};
use google_cloud_storage::http::object_access_controls::patch::PatchObjectAccessControlRequest;


async fn run(client:Client) {

    let result = client.patch_object_access_control(&PatchObjectAccessControlRequest{
        bucket: "bucket".to_string(),
        object: "filename".to_string(),
        entity: "allAuthenticatedUsers".to_string(),
        acl: ObjectAccessControl {
            role: ObjectACLRole::READER,
            ..Default::default()
        },
        ..Default::default()
    }).await;
}
source

pub async fn delete_object_access_control( &self, req: &DeleteObjectAccessControlRequest ) -> Result<(), Error>

Deletes the bucket ACL. https://cloud.google.com/storage/docs/json_api/v1/objectAccessControls/delete

use google_cloud_storage::client::Client;
use google_cloud_storage::http::object_access_controls::{ObjectAccessControl, ObjectACLRole};
use google_cloud_storage::http::object_access_controls::delete::DeleteObjectAccessControlRequest;

async fn run(client:Client) {
    let result = client.delete_object_access_control(&DeleteObjectAccessControlRequest{
        bucket: "bucket".to_string(),
        object: "filename".to_string(),
        entity: "allAuthenticatedUsers".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn list_notifications( &self, req: &ListNotificationsRequest ) -> Result<ListNotificationsResponse, Error>

Lists the notification. https://cloud.google.com/storage/docs/json_api/v1/notifications/list

use google_cloud_storage::client::Client;
use google_cloud_storage::http::notifications::list::ListNotificationsRequest;

async fn run(client:Client) {
    let result = client.list_notifications(&ListNotificationsRequest{
        bucket: "bucket".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn get_notification( &self, req: &GetNotificationRequest ) -> Result<Notification, Error>

Gets the notification. https://cloud.google.com/storage/docs/json_api/v1/notifications/get

use google_cloud_storage::client::Client;
use google_cloud_storage::http::notifications::get::GetNotificationRequest;


async fn run(client:Client) {

    let result = client.get_notification(&GetNotificationRequest{
        bucket: "bucket".to_string(),
        notification: "notification".to_string()
    }).await;
}
source

pub async fn insert_notification( &self, req: &InsertNotificationRequest ) -> Result<Notification, Error>

Inserts the notification. https://cloud.google.com/storage/docs/json_api/v1/notifications/insert

use google_cloud_storage::client::Client;
use google_cloud_storage::http::notifications::EventType;
use google_cloud_storage::http::notifications::insert::{InsertNotificationRequest, NotificationCreationConfig};


async fn run(client:Client) {

    let result = client.insert_notification(&InsertNotificationRequest {
        bucket: "bucket".to_string(),
        notification: NotificationCreationConfig {
            topic: format!("projects/{}/topics/{}", "project","bucket"),
            event_types: Some(vec![EventType::ObjectMetadataUpdate, EventType::ObjectDelete]),
            ..Default::default()
        }
    }).await;
}
source

pub async fn delete_notification( &self, req: &DeleteNotificationRequest ) -> Result<(), Error>

Deletes the notification. https://cloud.google.com/storage/docs/json_api/v1/notifications/delete

use google_cloud_storage::client::Client;
use google_cloud_storage::http::notifications::delete::DeleteNotificationRequest;


async fn run(client:Client) {

    let result = client.delete_notification(&DeleteNotificationRequest {
        bucket: "bucket".to_string(),
        notification: "notification".to_string()
    }).await;
}
source

pub async fn list_hmac_keys( &self, req: &ListHmacKeysRequest ) -> Result<ListHmacKeysResponse, Error>

Lists the hmac keys. https://cloud.google.com/storage/docs/json_api/v1/projects/hmacKeys/list

use google_cloud_storage::client::Client;
use google_cloud_storage::http::hmac_keys::list::ListHmacKeysRequest;


async fn run(client:Client) {

    let result = client.list_hmac_keys(&ListHmacKeysRequest {
        project_id: "project_id".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn get_hmac_key( &self, req: &GetHmacKeyRequest ) -> Result<HmacKeyMetadata, Error>

Gets the hmac keys. https://cloud.google.com/storage/docs/json_api/v1/projects/hmacKeys/get

use google_cloud_storage::client::Client;
use google_cloud_storage::http::hmac_keys::get::GetHmacKeyRequest;


async fn run(client:Client) {

    let result = client.get_hmac_key(&GetHmacKeyRequest {
        access_id: "access_id".to_string(),
        project_id: "project_id".to_string(),
    }).await;
}
source

pub async fn create_hmac_key( &self, req: &CreateHmacKeyRequest ) -> Result<CreateHmacKeyResponse, Error>

Creates the hmac key. https://cloud.google.com/storage/docs/json_api/v1/projects/hmacKeys/create

use google_cloud_storage::client::Client;
use google_cloud_storage::http::hmac_keys::create::CreateHmacKeyRequest;


async fn run(client:Client) {

    let result = client.create_hmac_key(&CreateHmacKeyRequest {
        service_account_email: "service_account_email".to_string(),
        project_id: "project".to_string(),
    }).await;
}
source

pub async fn update_hmac_key( &self, req: &UpdateHmacKeyRequest ) -> Result<HmacKeyMetadata, Error>

Updates the hmac key. https://cloud.google.com/storage/docs/json_api/v1/projects/hmacKeys/update

use google_cloud_storage::client::Client;
use google_cloud_storage::http::hmac_keys::HmacKeyMetadata;
use google_cloud_storage::http::hmac_keys::update::UpdateHmacKeyRequest;


async fn run(client:Client) {

    let result = client.update_hmac_key(&UpdateHmacKeyRequest{
        access_id: "access_id".to_string(),
        project_id: "project_id".to_string(),
        metadata: HmacKeyMetadata {
            state: "INACTIVE".to_string(),
            ..Default::default()
        },
    }).await;
}
source

pub async fn delete_hmac_key( &self, req: &DeleteHmacKeyRequest ) -> Result<(), Error>

Deletes the hmac key. https://cloud.google.com/storage/docs/json_api/v1/projects/hmacKeys/delete

use google_cloud_storage::client::Client;
use google_cloud_storage::http::hmac_keys::delete::DeleteHmacKeyRequest;


async fn run(client:Client) {

    let result = client.delete_hmac_key(&DeleteHmacKeyRequest{
        access_id: "access_id".to_string(),
        project_id:"project_id".to_string(),
    }).await;
}
source

pub async fn list_objects( &self, req: &ListObjectsRequest ) -> Result<ListObjectsResponse, Error>

Lists the objects. https://cloud.google.com/storage/docs/json_api/v1/objects/list

use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::list::ListObjectsRequest;


async fn run(client:Client) {

    let result = client.list_objects(&ListObjectsRequest{
        bucket: "bucket".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn get_object(&self, req: &GetObjectRequest) -> Result<Object, Error>

Gets the object. https://cloud.google.com/storage/docs/json_api/v1/objects/get

use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::get::GetObjectRequest;

async fn run(client:Client) {
    let result = client.get_object(&GetObjectRequest{
        bucket: "bucket".to_string(),
        object: "object".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn copy_object( &self, req: &CopyObjectRequest ) -> Result<Object, Error>

Copy the object. https://cloud.google.com/storage/docs/json_api/v1/objects/copy

use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::copy::CopyObjectRequest;

async fn run(client:Client) {
    let result = client.copy_object(&CopyObjectRequest{
        source_bucket: "bucket".to_string(),
        destination_bucket: "bucket".to_string(),
        destination_object: "object".to_string(),
        source_object: "object".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn download_object( &self, req: &GetObjectRequest, range: &Range ) -> Result<Vec<u8>, Error>

Download the object. https://cloud.google.com/storage/docs/json_api/v1/objects/get alt is always media

use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::get::GetObjectRequest;
use google_cloud_storage::http::objects::download::Range;


async fn run(client:Client) {

    let result = client.download_object(&GetObjectRequest{
        bucket: "bucket".to_string(),
        object: "object".to_string(),
        ..Default::default()
    }, &Range::default()).await;
}
source

pub async fn download_streamed_object( &self, req: &GetObjectRequest, range: &Range ) -> Result<impl Stream<Item = Result<Bytes, Error>>, Error>

Download the object. https://cloud.google.com/storage/docs/json_api/v1/objects/get alt is always media

use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::get::GetObjectRequest;
use google_cloud_storage::http::objects::download::Range;

async fn run(client:Client) {
    let result = client.download_streamed_object(&GetObjectRequest{
        bucket: "bucket".to_string(),
        object: "object".to_string(),
        ..Default::default()
    }, &Range::default()).await;

    //  while let Some(v) = downloaded.next().await? {
    //      let d: bytes::Bytes = v.unwrap();
    //  }
}
source

pub async fn upload_object<T: Into<Body>>( &self, req: &UploadObjectRequest, data: T, upload_type: &UploadType ) -> Result<Object, Error>

Uploads the object. https://cloud.google.com/storage/docs/json_api/v1/objects/insert

use std::collections::HashMap;
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::Object;
use google_cloud_storage::http::objects::upload::{Media, UploadObjectRequest, UploadType};

async fn run_simple(client:Client) {
    let upload_type = UploadType::Simple(Media::new("filename"));
    let result = client.upload_object(&UploadObjectRequest{
        bucket: "bucket".to_string(),
        ..Default::default()
    }, "hello world".as_bytes(), &upload_type).await;
}

async fn run_multipart(client:Client) {
    let mut metadata = HashMap::<String, String>::new();
    metadata.insert("key1".to_string(), "value1".to_string());
    let upload_type = UploadType::Multipart(Box::new(Object {
        name: "test1_meta".to_string(),
        content_type: Some("text/plain".to_string()),
        metadata: Some(metadata),
        ..Default::default()
    }));
    let result = client.upload_object(&UploadObjectRequest{
        bucket: "bucket".to_string(),
        ..Default::default()
    }, "hello world".as_bytes(), &upload_type).await;
}
source

pub fn get_resumable_upload(&self, url: String) -> ResumableUploadClient

Creates resumable upload from known URL.

Assumes URL is correct, if not, ResumableUploadClient is not guaranteed to perform correctly.

source

pub async fn prepare_resumable_upload( &self, req: &UploadObjectRequest, upload_type: &UploadType ) -> Result<ResumableUploadClient, Error>

Perform resumable uploads https://cloud.google.com/storage/docs/performing-resumable-uploads

use std::collections::HashMap;
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::Object;
use google_cloud_storage::http::objects::upload::{Media, UploadObjectRequest, UploadType};
use google_cloud_storage::http::resumable_upload_client::{ChunkSize, UploadStatus};

async fn run_simple(client:Client) {
    let upload_type = UploadType::Simple(Media::new("filename"));
    let uploader = client.prepare_resumable_upload(&UploadObjectRequest{
        bucket: "bucket".to_string(),
        ..Default::default()
    }, &upload_type).await.unwrap();

    // We can also use upload_multiple_chunk.
    let data = [1,2,3,4,5];
    let result = uploader.upload_single_chunk(Vec::from(data), data.len()).await;
}

async fn run_with_metadata(client:Client) {
    let mut metadata = HashMap::<String, String>::new();
    metadata.insert("key1".to_string(), "value1".to_string());
    let upload_type = UploadType::Multipart(Box::new(Object {
        name: "test1_meta".to_string(),
        content_type: Some("text/plain".to_string()),
        metadata: Some(metadata),
        ..Default::default()
    }));
    let uploader = client.prepare_resumable_upload(&UploadObjectRequest{
        bucket: "bucket".to_string(),
        ..Default::default()
    }, &upload_type).await.unwrap();

    let chunk1_data : Vec<u8>= (0..256 * 1024).map(|i| (i % 256) as u8).collect();
    let chunk2_data : Vec<u8>= (1..256 * 1024 + 50).map(|i| (i % 256) as u8).collect();
    let chunk1_size = chunk1_data.len() as u64;
    let chunk2_size = chunk2_data.len() as u64;
    let total_size = Some(chunk1_size + chunk2_size);

    // The chunk size should be multiple of 256KiB, unless it's the last chunk that completes the upload.
    let chunk1 = ChunkSize::new(0, chunk1_size - 1, total_size.clone());
    let status1 = uploader.upload_multiple_chunk(chunk1_data.clone(), &chunk1).await.unwrap();
    assert_eq!(status1, UploadStatus::ResumeIncomplete);

    let chunk2 = ChunkSize::new(chunk1_size, chunk1_size + chunk2_size - 1, total_size.clone());
    let status2 = uploader.upload_multiple_chunk(chunk2_data.clone(), &chunk2).await.unwrap();
    assert!(matches!(status2, UploadStatus::Ok(_)));
}
source

pub async fn upload_streamed_object<S>( &self, req: &UploadObjectRequest, data: S, upload_type: &UploadType ) -> Result<Object, Error>
where S: TryStream + Send + Sync + 'static, S::Error: Into<Box<dyn Error + Send + Sync>>, Bytes: From<S::Ok>,

Uploads the streamed object. https://cloud.google.com/storage/docs/json_api/v1/objects/insert

use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::upload::{Media, UploadObjectRequest, UploadType};

async fn run(client:Client) {
    let source = vec!["hello", " ", "world"];
    let size = source.iter().map(|x| x.len() as u64).sum();
    let chunks: Vec<Result<_, ::std::io::Error>> = source.clone().into_iter().map(|x| Ok(x)).collect();
    let stream = futures_util::stream::iter(chunks);
    let mut media = Media::new("filename");
    media.content_length = Some(size);
    let mut upload_type = UploadType::Simple(media);
    let result = client.upload_streamed_object(&UploadObjectRequest{
        bucket: "bucket".to_string(),
        ..Default::default()
    }, stream, &upload_type).await;
}
source

pub async fn patch_object( &self, req: &PatchObjectRequest ) -> Result<Object, Error>

Patches the object. https://cloud.google.com/storage/docs/json_api/v1/objects/patch

use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::patch::PatchObjectRequest;


async fn run(client:Client) {

    let result = client.patch_object(&PatchObjectRequest{
        bucket: "bucket".to_string(),
        object: "object".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn delete_object( &self, req: &DeleteObjectRequest ) -> Result<(), Error>

Deletes the object. https://cloud.google.com/storage/docs/json_api/v1/objects/delete

use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::delete::DeleteObjectRequest;


async fn run(client:Client) {

    let result = client.delete_object(&DeleteObjectRequest{
        bucket: "bucket".to_string(),
        object: "object".to_string(),
        ..Default::default()
    }).await;
}
source

pub async fn rewrite_object( &self, req: &RewriteObjectRequest ) -> Result<RewriteObjectResponse, Error>

Rewrites the object. https://cloud.google.com/storage/docs/json_api/v1/objects/rewrite

use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::rewrite::RewriteObjectRequest;


async fn run(client:Client) {
    let mut done = false;
    let mut rewrite_token = None;

    while !done {
        let result = client.rewrite_object(&RewriteObjectRequest{
            source_bucket: "bucket1".to_string(),
            source_object: "object".to_string(),
            destination_bucket: "bucket2".to_string(),
            destination_object: "object1".to_string(),
            rewrite_token: rewrite_token.clone(),
            ..Default::default()
        }).await.unwrap();

        done = result.done;
        rewrite_token = result.rewrite_token;
    }
}
source

pub async fn compose_object( &self, req: &ComposeObjectRequest ) -> Result<Object, Error>

Composes the object. https://cloud.google.com/storage/docs/json_api/v1/objects/compose

use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::compose::{ComposeObjectRequest, ComposingTargets};
use google_cloud_storage::http::objects::rewrite::RewriteObjectRequest;
use google_cloud_storage::http::objects::SourceObjects;

async fn run(client:Client) {
    let result = client.compose_object(&ComposeObjectRequest{
        bucket: "bucket1".to_string(),
        destination_object: "object1".to_string(),
        composing_targets: ComposingTargets {
            source_objects: vec![SourceObjects {
                name: "src".to_string(),
                ..Default::default()
            }],
            ..Default::default()
        },
        ..Default::default()
    }).await;
}

Trait Implementations§

source§

impl Clone for StorageClient

source§

fn clone(&self) -> StorageClient

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more