简体   繁体   English

Azure-Blob存储

[英]Azure - Blob Storage

I've the following scenario.... I am trying to download a file from a site with credentials and store it in the Azure Blob Storage. 我有以下情形:...我试图从具有凭据的站点下载文件并将其存储在Azure Blob存储中。

For this I've created a app. 为此,我创建了一个应用程序。 Using the credentials I am able to access the file and download the file. 使用凭据,我可以访问文件并下载文件。

For this I've used WebClient. 为此,我使用了WebClient。

NetworkCredential credentials = new NetworkCredential(userName, password);
CredentialCache cCache = new CredentialCache();
cCache.Add(new Uri(fileURL), "Basic", credentials);

WebClient wClient = new WebClient();
wClient.Credentials = cCache;
wClient.DownloadFile(fileUrl, fileName);

Using the above code I was able to download the file onto the machine on the cloud. 使用上面的代码,我能够将文件下载到云上的计算机上。 But I want to store it in the Blob Storage container. 但我想将其存储在Blob存储容器中。

How do I do this.? 我该怎么做呢。?

Thx 谢谢

WebClient.DownloadFile downloads the file to the path specified in the second parameter. WebClient.DownloadFile将文件下载到第二个参数中指定的路径。 In your case, I would like to suggest you to use the DownloadData method, which returns a byte array. 对于您的情况,我建议您使用DownloadData方法,该方法返回一个字节数组。 Then you can use CloudBlob.UploadByteArray to upload the byte array to blob: http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.storageclient.cloudblob.uploadbytearray . 然后,您可以使用CloudBlob.UploadByteArray将字节数组上载到blob: http : //msdn.microsoft.com/zh-cn/library/windowsazure/microsoft.windowsazure.storageclient.cloudblob.uploadbytearray

Best Regards, 最好的祝福,

Ming Xu. 徐明

MSDN search "c# .net upload file to azure storage" MSDN搜索“ C#.net将文件上传到Azure存储”

azure upload 天蓝色上传

Can you get you file into a stream? 您可以将文件放入流中吗?

BlobUploadStream BlobUploadStream

WebClientToStream WebClientToStream

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM