Windows Azure : Creation of a file on cloud blob container

标签 windows azure blob

我正在编写一个将在云上执行的程序。该程序将生成应写入文件的输出,并且该文件应保存在 blob 容器中。

我不知道该怎么做

这段代码

FileStream fs = new FileStream(file, FileMode.Create);
        StreamWriter sw = new StreamWriter(fs);

在云端生成名为“file”的文件...

<小时/>

哦..那么如何将内容存储到blob..

最佳答案

您是否正在尝试上传页面 blob 或 block blob?通常需要 block blob,除非您要从 blob 镜像创建 VM,否则需要页 blob。

但是这样的东西是有效的。此片段取自最优秀的Blob Transfer Utility检查一下它是否满足您所有的上传和下载 blob 需求。 (如果您需要 VHD,只需将类型从“ block 到页面”更改)

public void UploadBlobAsync(ICloudBlob blob, string LocalFile)
    {
        // The class currently stores state in class level variables so calling UploadBlobAsync or DownloadBlobAsync a second time will cause problems.
        // A better long term solution would be to better encapsulate the state, but the current solution works for the needs of my primary client.
        // Throw an exception if UploadBlobAsync or DownloadBlobAsync has already been called.
        lock (WorkingLock)
        {
            if (!Working)
                Working = true;
            else
                throw new Exception("BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer.");
        }

        // Attempt to open the file first so that we throw an exception before getting into the async work
        using (FileStream fstemp = new FileStream(LocalFile, FileMode.Open, FileAccess.Read)) { }

        // Create an async op in order to raise the events back to the client on the correct thread.
        asyncOp = AsyncOperationManager.CreateOperation(blob);

        TransferType = TransferTypeEnum.Upload;
        m_Blob = blob;
        m_FileName = LocalFile;

        var file = new FileInfo(m_FileName);
        long fileSize = file.Length;

        FileStream fs = new FileStream(m_FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
        ProgressStream pstream = new ProgressStream(fs);
        pstream.ProgressChanged += pstream_ProgressChanged;
        pstream.SetLength(fileSize);
        m_Blob.ServiceClient.ParallelOperationThreadCount = 10;
        asyncresult = m_Blob.BeginUploadFromStream(pstream, BlobTransferCompletedCallback, new BlobTransferAsyncState(m_Blob, pstream));
    }

关于Windows Azure : Creation of a file on cloud blob container,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2618899/

相关文章:

windows - 使用批处理命令检查文件夹是否为空?

azure - 使用 COPY INTO 和 Azure Databricks 处理 abfss 中的空格

ios - 将图像从 Online mysql 数据库加载到 UICollectionView Swift

mysql通过存储过程插入blob数据的语法

c# - 自定义控件退出时光标未更改

java - 使用java将本地文件复制并执行到带有windows和linux的远程服务器

windows - Windows 窗口类区分大小写吗?

c# - Azure 认知服务 - 为什么我无权访问服务? (401错误)

android - 使用 Azure KeyVault 进行 React Native

java - 通过Java从MySQL数据库下载BLOB数据