无法下载上传到blob存储的文件

时间:2015-02-22 16:43:07

标签: azure file-upload blob azure-storage azure-storage-blobs

我在azure存储上创建了容器,下面的代码使得我可以在容器中上传我的文件(blob)。现在它说上传成功,但我无法弄清楚如何到达这些文件下载它。互联网上没有关于它的文件。

任何帮助都将得到解决。

//  create Azure Storage
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=bireddy;AccountKey=8OMbjBeJR+SIYaSt0YtBUzivLKPX5ZbsGJeEY9vsX0BPbX3uy9KxOckK7LuLeH3ZbOh+NoEaiEIV/NWvZbFOrA==");

//  create a blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

//  create a container 
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

// make it public
container.SetPermissions(
    new BlobContainerPermissions {
        PublicAccess = BlobContainerPublicAccessType.Container
    }); 

//  create a block blob
CloudBlockBlob blockBlob = container.GetBlockBlobReference(FileUpload1.FileName);

//  upload to Azure Storage
//  this has to be changed sometime later

blockBlob.Properties.ContentType = FileUpload1.PostedFile.ContentType;
blockBlob.UploadFromStream(FileUpload1.FileContent);

感谢您的讨论。

2 个答案:

答案 0 :(得分:1)

有许多选项可供下载blob:

使用PowerShell:请参阅此处的Azure Storage Powershell指南:     http://azure.microsoft.com/en-us/documentation/articles/storage-powershell-guide-full/

使用命令行:请在此处查看AzCopy工具的文档:     http://aka.ms/azcopy

使用您的C#代码:这里有一个指南,其中包含有关如何下载blob的部分:     http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-blobs/

使用基于GUI的资源管理器:有许多第三方资源管理器,其中一些列在此处:     http://blogs.msdn.com/b/windowsazurestorage/archive/2014/03/11/windows-azure-storage-explorers-2014.aspx

答案 1 :(得分:0)

//解析连接字符串并返回对存储帐户的引用。             CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting(“StorageConnectionString”));

        //Create the Blob service client
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        // Retrieve a reference to a container.
        CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

        // Retrieve reference to a blob named            
        CloudBlockBlob blockBlob2 = container.GetBlockBlobReference(document);

        //using (var np = File.Open(@"C:\mydocuments\"+ document, FileMode.Create))
        //    blockBlob2.DownloadToStream(np, null, options, null);
        byte[] fileBytes;
        using (var fileStream = new MemoryStream())
        {
            blockBlob2.DownloadToStream(fileStream, null, options, null);
            fileBytes = fileStream.ToArray();
        }
        return fileBytes;