Spa*_*dan 1 azure azure-storage azure-storage-blobs
我在我的Azure存储account.Now上传文本文件中,在我的辅助角色,我需要做的是在每次运行时,它将从数据库中的一些内容,而且内容必须在上传文本文件写入,具体来说,每次文本文件的内容都应该被一些新内容覆盖.
在这里,他们给的方式到一个文本文件上传到您的存储空间,并且删除file.But我不想这样做,需要每次只需要修改已经存在的文本文件.
I'm assuming you're referring to storing a file in a Windows Azure blob. If that's the case: A blob isn't a file system; it's just a place to store data (and the notion of a file is a bit artificial - it's just... a blob stored in a bunch of blocks).
To modify the file, you would need to download it and save it to local disk, modify it (again, on local disk), then do an upload. A few thoughts on this:
Just to make sure this download/modify/upload pattern is clear, here's a very simple example (I just typed this up quickly in Visual Studio but haven't tested it. Just trying to illustrate the point):
// initial setup
var acct = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
var client = acct.CreateCloudBlobClient();
// what you'd call each time you need to update a file stored in a blob
var blob = client.GetContainerReference("mycontainer").GetBlockBlobReference("myfile.txt");
using (var fileStream = System.IO.File.OpenWrite(@"path\myfile.txt"))
{
blob.DownloadToStream(fileStream);
}
// ... modify file...
// upload modified file
using (var fileStream = System.IO.File.OpenWrite(@"path\myfile.txt"))
{
blob.UploadFromStream(fileStream);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7600 次 |
| 最近记录: |