【发布时间】:2017-09-23 03:14:44
【问题描述】:
根据标题,我有一个程序,我正在尝试使用 PutBlock 方法添加到现有的 BlobkBlob:
private static void UploadNewText(string text)
{
string fileName = "test4.txt";
string containerString = "mycontainer";
CloudStorageAccount storage = CloudStorageAccount.Parse(connection);
CloudBlobClient client = storage.CreateCloudBlobClient();
CloudBlobContainer container = client.GetContainerReference(containerString);
CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
using (MemoryStream stream = new MemoryStream())
using (StreamWriter sw = new StreamWriter(stream))
{
sw.Write(text);
sw.Flush();
stream.Position = 0;
string blockId = Convert.ToBase64String(
ASCIIEncoding.ASCII.GetBytes("0000005"));
Console.WriteLine(blockId);
blob.PutBlock(blockId, stream, null);
blob.PutBlockList(new string[] { blockId });
}
}
据我了解,如果 BlockId 增加(或至少不同)并且大小一致,这应该可以工作;但是,当我为同一个文件再次运行它时(无论我是否增加块 ID),它只会用新文本覆盖现有文件。
我意识到还有其他选项可以附加到 blob(例如 AppendBlob),但我很好奇 PutBlock 是否可以做到这一点。我正在尝试做的事情是否可行?如果可以,我做错了什么?
【问题讨论】:
标签: c# azure azure-blob-storage