Azure Storage Blob 属性设置

概述

在使用SDK做Blob对象属性的获取或设置时,如果只是直接使用get或set方法,是无法成功获取或设置blob对象的属性。主要是因为在获取对象时,对象的属性默认并未被填充到对象,这就需要执行额外的方法将对象的属性填充给对象;而在设置Blob对象属性时,程序默认只是保存到了本地,并未提交到Server端,所以需要执行额外的方法将修改提交到Server端。

下面分别给出JAVA和C#的SDK获取、设置Blob对象属性的示例。

JAVA Code Sample

//get content type
blob2.downloadAttributes();
System.out.println(blob2.getProperties().getContentType());

//set content type
String contentType = "image"; //image/jpeg
blob2.getProperties().setContentType(contentType);
blob2.uploadProperties();

C# Code Sample

//get property
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName);
blockBlob.FetchAttributes();
Console.WriteLine("ContentType: " + blockBlob.Properties.ContentType);

//set property
blockBlob.Properties.ContentType = "property test";
blockBlob.SetProperties();

SDK参考

azure-storage-java

azure-storage-net

猜你喜欢

转载自www.cnblogs.com/taro/p/9640359.html