azure-storage – 在Windows Azure Blob存储中使用子目录
发布时间:2020-12-14 05:46:37 所属栏目:Windows 来源:网络整理
导读:我正在尝试将文件上传到 Windows Azure blob存储.根据我的理解,您可以将文件上传到类似于子目录的内容.我想将文件上传到blob,使文件基本上驻留在/TestContainer/subDirectory1/subDirectory2/file.png中 // Setup the Windows Aure blob clientCloudStorageA
我正在尝试将文件上传到
Windows Azure blob存储.根据我的理解,您可以将文件上传到类似于子目录的内容.我想将文件上传到blob,使文件基本上驻留在/TestContainer/subDirectory1/subDirectory2/file.png中
// Setup the Windows Aure blob client CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting("BlobStorage"); CloudBlobClient client = storageAccount.CreateCloudBlobClient(); // Retrieve the TestContainer container from blob storage CloudBlobContainer container = client.GetContainerReference("TestContainer"); if (container.CreateIfNotExist()) container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); // Setup the blob CloudBlob blob = container.GetBlobReference(""); // Create the meta data for the blob NameValueCollection metadata = new NameValueCollection(); metadata["id"] = fileID.ToString(); blob.Metadata.Add(metadata); // Store the blob byte[] bytes = GetFileBytes(); blob.UploadByteArray(bytes); 如何上传具有目录结构的文件?链接here提到有一种方法可以做到这一点.但是,它没有告诉你如何做到这一点. 谢谢! 解决方法
有几种方法.更简单的方法是使用/ maker作为@ makerofthings7已经提到过.如果您愿意,也可以使用CloudBlobDirectory对象.这是一个显示两者的例子.
CloudBlobContainer testContainer = blobClient.GetContainerReference("testcontainer"); //Upload using a CloudBlobDirectory object var dir = testContainer.GetDirectoryReference("UsingCloudDirectory/foo/bar/baz/"); var blobRef = dir.GetBlockBlobReference("BlobByDir.bin"); using (MemoryStream ms = new MemoryStream(new byte[] { 0x0 })) { blobRef.UploadFromStream(ms); } //Upload using the filename without a CloudBlobDirectory var blobRef2 = testContainer.GetBlockBlobReference("UsingBlobName/foo/bar/baz/BlobByName.bin"); using (MemoryStream ms = new MemoryStream(new byte[] { 0x0 })) { blobRef2.UploadFromStream(ms); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Windows XP全盘加密 – 有哪些选择?
- wix – 当MSI日志文件显示“Note:1:2729”时,它是什么意思
- 部署 – MSDeploy是否“足够友好”,或者它可以包装在MSI文件
- Windows Server 2008 R2上本机支持的远程文件传输的选项
- 关于WIN10连接WIN7共享打印机的方法
- Windows 8 – Windows 8模拟器不起作用
- windows – 用于推送通知的WNS或MPNS?
- 对于在Windows Server 2008(sp1)上运行的Delphi应用程序,内
- batch-file – 一个批处理文件如何获取另一个批处理文件的退
- Windows支持的语言开箱即用