Azure / azure-sdk-for-rust

This repository is for active development of the *unofficial* Azure SDK for Rust. This repository is *not* supported by the Azure SDK team.
MIT License
676 stars 231 forks source link

BlobClient set_metadata() Example? #1672

Closed dalumedic closed 1 month ago

dalumedic commented 1 month ago

Hello

Thanks for the great SDK :-) I did search before posting this but, alas, could find no examples of setting metadata for a blob. I'm am still learning Rust so apologies for missing anything that should be obvious.

I am able to set tags on the blob with the easy to follow API but set_metadata diverges from the pattern and discovery of how to use it is eluding me.

Example:

let destination = DestinationStorageAccount::new();

let destination_service_client = BlobServiceClient::new(destination.name, destination.creds);

let destination_blob = destination_service_client
    .container_client(message.container.clone())
    .blob_client(message.blob.clone());

let meta_data_response = destination_blob.set_metadata().await?;

set_metadata() has no arguments to process the metadata one wishes to set. Where do we actually set the values?

The dotnet SDK has a way to set metadata and tags in the same request via BlobCopyFromUriOptions.

dalumedic commented 1 month ago

Figured it out.

Updated Example:

let destination = DestinationStorageAccount::new();

let destination_service_client = BlobServiceClient::new(destination.name, destination.creds);

let destination_blob = destination_service_client
    .container_client(message.container.clone())
    .blob_client(message.blob.clone());

let mut meta_data = Metadata::new();
meta_data.insert("test", "123");

let meta_data_builder: SetMetadataBuilder = destination_blob.set_metadata();
let meta_data_response = meta_data_builder.metadata(meta_data).await?;