windows 将文本附加到 Azure 中的 Blob
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3798588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Append text to Blob in Azure
提问by jlezard
After looking at this tutorial on blobs: channel 9, I was thinking of using a blob container to save a bunch of tweets (storing the json of each tweet that is). Ideally I would like to create a blob reference for each hour of the day, and append new tweets to this blob as they come in. The issue is that the method UploadText(string) overwrites the existing content of the blob, is there an easy way to append text to an existing blob ?
在查看关于 blob: channel 9 的教程后,我考虑使用 blob 容器来保存一堆推文(存储每条推文的 json)。理想情况下,我想为一天中的每个小时创建一个 blob 引用,并在它们进来时将新推文附加到这个 blob。问题是 UploadText(string) 方法覆盖了 blob 的现有内容,是否有一个简单的方法将文本附加到现有 blob 的方法?
Thanks!
谢谢!
fun (json:string) ->
let account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"))
let blobs = account.CreateCloudBlobClient();
let tempBlob = blobs.GetBlobReference("tweets/2010-9-26/17/201092617.txt")
tempBlob.Properties.ContentType <- "text/plain"
tempBlob.UploadText(json)
回答by Mikael Koskinen
Azure now supports Append Blobs. When you create a new blob, you must define it as an Append Block. You can't append to existing block blobs.
Azure 现在支持追加 Blob。创建新 blob 时,必须将其定义为 Append Block。您不能附加到现有的块 blob。
Here's some simple code which you can use.
这是您可以使用的一些简单代码。
Append:
附加:
CloudAppendBlob appendBlob = container.GetAppendBlobReference("myblob.txt")
appendBlob.AppendText("new line");
Read:
读:
appendBlob.DownloadText()
Technet contains a good tutorialon the subject. Also the official Azure documentationnow includes help for using Append Blob.
Technet 包含有关该主题的很好的教程。此外,官方 Azure 文档现在包括使用 Append Blob 的帮助。
回答by Taylor Bird
Page Blobsare the way to go for this need. (vs block blobs)
Page Blob是满足这种需求的方法。(与块 blob)
You create the blob with a Put Blob operation: http://msdn.microsoft.com/en-us/library/dd179451.aspx
您使用 Put Blob 操作创建 blob:http: //msdn.microsoft.com/en-us/library/dd179451.aspx
Then you can add "pages" using a Put page operation: http://msdn.microsoft.com/en-us/library/ee691975.aspx
然后您可以使用 Put 页面操作添加“页面”:http: //msdn.microsoft.com/en-us/library/ee691975.aspx
Page Blobs will amend the page(s) added with a put immediately, more accurately mimicking traditional file systems.
Page Blob 将立即修改添加了 put 的页面,更准确地模仿传统文件系统。
Block blobs are going to expect a more ridig construction, and require a two-phase submit/commit construction. Once compiled, you have to overwrite to ammend to the blob. Block blobs are designed for streaming of static (loose definition) content, vs as a read/write store. Page Blobs were added to support those scenarios.
块 blob 需要更严格的构造,并且需要两阶段提交/提交构造。编译后,您必须覆盖以修改 blob。块 blob 设计用于流式传输静态(松散定义)内容,而不是作为读/写存储。添加了页面 Blob 以支持这些场景。
回答by tishon
You can try getting the list of committed blocks via the CloudBlockBlob.DownloadBlockList()method and then append the new content via CloudBlockBlob.PutBlock().
您可以尝试通过CloudBlockBlob.DownloadBlockList()方法获取已提交块的列表,然后通过CloudBlockBlob.PutBlock()附加新内容。