输入文字在Azure存储的文件 [英] Write text to a file in Azure storage

查看:219
本文介绍了输入文字在Azure存储的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Azure存储account.Now上传文本文件中,在我的辅助角色,我需要做的是在每次运行时,它将从数据库中的一些内容,而且这些内容必须在上传写文本文件,具体而言,每次文本文件的内容应该与一些新的内容覆盖。

I have a text file uploaded in my Azure storage account.Now, in my worker role , what i need to do is every time it is run, it fetches some content from Database, and that content must be written in the Uploaded text file, specifically , each time the content of Text file should be overwritten with some new content.

这里,他们给一个方法到一个文本文件上传到您的存储,并删除file.But我不想这样做,只是需要修改已每次present文本文件。

Here, they have given a way to upload a text file to your storage and also delete a file.But i don't want to do that, need to just MODIFY the already present text file each time.

推荐答案

我假设你指的是存储在Windows Azure中的BLOB文件。如果是这样的话:一个blob不是一个文件系统;它只是一个存储数据的地方(和文件的概念是有点做作 - 它只是......存储在一堆块的BLOB)。

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:


  • 为此,你应该你的工人角色的配置中分配一个本地磁盘。该盘将是一个逻辑磁盘,你的虚拟机上运行的机器内的本地物理磁盘上创建。换句话说,它会为这种类型的使用进行附加存储和完美。

  • 您的虚拟机实例和存储之间的带宽是<击>每核的100Mbps。因此,抓住一个10MB的文件,同时在一个小实例,将采取可能一秒钟。在一个XL,或许围绕一个十分之一秒。的真快,并与VM系列(A,D,G)和大小不同而不同。

  • 因为你的文件是Blob存储,如果你觉得这样的倾向这样做(或有此需要),你可以采取快照上传更新版本之前。快照是像链接列表来存储的数据块。而且也没有成本的快照,直到有一天,你进行了更改现有数据(现在你必须重新块presenting新旧数据)。一个很好的方式对一个blob按BLOB基础上斑点的preserve版本(和它的琐碎删除快照)。

  • For this purpose, you should allocate a local disk within your worker role's configuration. This disk will be a logical disk, created on a local physical disk within the machine your vm is running on. In other words, it'll be attached storage and perfect for this type of use.
  • The bandwidth between your vm instance and storage is 100Mbps per core. So, grabbing a 10MB file, while on a Small instance, would take maybe a second. On an XL, maybe around a tenth of a second. really fast, and varies with VM series (A, D, G) and size.
  • Because your file is in blob storage, if you felt so inclined to do so (or had the need for this), you could take a snapshot prior to uploading an updated version. Snapshots are like link-lists to your stored data blocks. And there's no cost to snapshots until, one day, you make a change to existing data (and now you'd have blocks representing both old and new data). An excellent way to preserve versions of a blob on a blob-by-blob basis (and it's trivial to delete snapshots).

只是为了确保此下载/修改/上传模式是明确的,这里有一个很简单的例子(我只是在Visual Studio中键入这件事很快,但还没有测试它只是想说明这一点。):

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);
        }

这篇关于输入文字在Azure存储的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆