上传多个文件天青Blob存储 [英] Uploading Multiple Files to Azure Blob Storage
问题描述
漂亮的新的Windows Azure。我已经按照这个教程:的教程。它完美但是一个限制是对我心目中的应用程序,它需要有可能相对快速地上传多个文件。
Pretty new to 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.
是否有可能修改教程,支持多文件上传,例如用户可以使用Shift键并单击选择多个文件。
Is it possible to modify the tutorial to support multi-file uploads, e.g. The user can use shift-click to select multiple files..
或者,如果任何人任何好的教程,详细说明上述?
Or if anyone knows of any good tutorials detailing the above?
任何帮助表示赞赏,
感谢
推荐答案
我想看看从DotNetCurry这个教程它展示了如何使用创建多文件上传jQuery来处理文件的多个上传到ASP.NET页面。它使用ASP.NET 3.5建的,但如果你使用.NET 4中不应该的问题 - 没有什么太疯狂了事情
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. 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.
但关键是, jQuery的插件,可以让你的文件集合上传到服务器上。在ASP.NET代码后面将处理由通过 Request.Files
收集循环:
But the key is that the jQuery plug-in will allow you to upload a collection of files to the server. The ASP.NET code behind will handle that by looping through the Request.Files
collection:
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/>");
}
}
您会将此代码放在您的教程在 insertButton_Click
事件处理程序 - 本质把斑点创作并上传到Blob存储里面,上面的代码的如果(hpf.ContentLength大于0)
块
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.
所以伪代码可能看起来像:
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!
这篇关于上传多个文件天青Blob存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!