概述

在使用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

相关文章:

  • 2021-12-20
  • 2022-03-07
  • 2021-11-21
  • 2022-12-23
  • 2021-11-25
  • 2021-10-20
猜你喜欢
  • 2021-05-03
  • 2021-09-23
  • 2021-08-09
  • 2021-08-10
  • 2022-02-15
  • 2021-07-03
相关资源
相似解决方案