简体   繁体   English

将多个文件上载到Azure Blob存储

[英]Uploading Multiple Files to Azure Blob Storage

Pretty new to Windows Azure. 对Windows Azure来说很新鲜。 I've followed this tutorial: tutorial . 我已经按照本教程: 教程 It works perfectly however one limitation is that for the application I have in mind, it would need to be possible to upload multiple files relatively quickly. 它完美地工作但是一个限制是,对于我想到的应用程序,需要能够相对快速地上传多个文件。

Is it possible to modify the tutorial to support multi-file uploads, eg The user can use shift-click to select multiple files.. 是否可以修改教程以支持多文件上传,例如,用户可以使用shift-click选择多个文件。

Or if anyone knows of any good tutorials detailing the above? 或者,如果有人知道任何好的教程详细说明上述内容?

Any help is appreciated, 任何帮助表示赞赏,

Thanks 谢谢

I'd take a look at this tutorial from DotNetCurry which shows how to create a multiple file upload using jQuery to handle the multiple uploading of files to an ASP.NET page. 我将看看DotNetCurry的这个教程 ,该教程展示了如何使用jQuery创建多文件上传来处理多个文件上传到ASP.NET页面。 It's built using ASP.NET 3.5, but it shouldn't matter if you're using .NET 4 - there's nothing too crazy going on. 它是使用ASP.NET 3.5构建的,但是如果你使用的是.NET 4并不重要 - 没有什么太疯狂了。

But the key is that the jQuery plug-in will allow you to upload a collection of files to the server. 但关键是jQuery插件允许您将一组文件上传到服务器。 The ASP.NET code behind will handle that by looping through the Request.Files collection: 后面的ASP.NET代码将通过循环遍历Request.Files集合来处理它:

    HttpFileCollection hfc = Request.Files;
    for (int i = 0; i < hfc.Count; i++)
    {
        HttpPostedFile hpf = hfc[i];
        if (hpf.ContentLength > 0)
        {
            hpf.SaveAs(Server.MapPath("MyFiles") + "\\" +
              System.IO.Path.GetFileName(hpf.FileName));
            Response.Write("<b>File: </b>" + hpf.FileName + " <b>Size:</b> " +
                hpf.ContentLength + " <b>Type:</b> " + hpf.ContentType + " Uploaded Successfully <br/>");
        }
    }

You would put this code in your tutorial in the insertButton_Click event handler - essentially putting the blob creation and uploading to blob storage inside the above code's if(hpf.ContentLength>0) block. 您可以将此代码放在insertButton_Click事件处理程序的教程中 - 基本上将blob创建并上传到blob存储在上面的代码的if(hpf.ContentLength>0)块中。

So pseudo-code may look like: 所以伪代码可能看起来像:

protected void insertButton_Click(object sender, EventArgs e)
{
    HttpFileCollection hfc = Request.Files;
    for (int i = 0; i < hfc.Count; i++)
    {
      HttpPostedFile hpf = hfc[i];

      // Make a unique blob name
      string extension = System.IO.Path.GetExtension(hpf.FileName);

      // Create the Blob and upload the file
      var blob = _BlobContainer.GetBlobReference(Guid.NewGuid().ToString() + extension);
      blob.UploadFromStream(hpf.InputStream);

      // Set the metadata into the blob
      blob.Metadata["FileName"] = fileNameBox.Text;
      blob.Metadata["Submitter"] = submitterBox.Text;
      blob.SetMetadata();

      // Set the properties
      blob.Properties.ContentType = hpf.ContentType;
      blob.SetProperties();
    }
}

Again, it's just pseudo-code, so I'm assuming that's how it would work. 同样,它只是伪代码,所以我假设它是如何工作的。 I didn't test the syntax, but I think it's close. 我没有测试语法,但我认为它很接近。

I hope this helps. 我希望这有帮助。 Good luck! 祝好运!

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

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