对于 Windows Azure 来说还很陌生。我已经按照这个教程进行操作:tutorial http://blogs.msdn.com/b/jnak/archive/2010/01/11/walkthrough-windows-azure-blob-storage-nov-2009-and-later.aspx。它工作得很好,但一个限制是,对于我想要的应用程序,需要能够相对快速地上传多个文件。
是否可以修改教程以支持多文件上传,例如用户可以使用 Shift 键单击来选择多个文件。
或者如果有人知道详细介绍上述内容的任何好的教程?
任何帮助表示赞赏,
Thanks
我想看看这个tutorial http://www.dotnetcurry.com/ShowArticle.aspx?ID=317来自 DotNetCurry,它展示了如何使用 jQuery 创建多个文件上传来处理向 ASP.NET 页面的多个文件上传。它是使用 ASP.NET 3.5 构建的,但如果您使用 .NET 4,也没关系 - 没有什么太疯狂的事情发生。
但关键是 jQuery 插件将允许您将文件集合上传到服务器。后面的 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/>");
}
}
您可以将此代码放在您的教程中insertButton_Click
事件处理程序 - 本质上是将 blob 创建并上传到上述代码的 blob 存储中if(hpf.ContentLength>0)
block.
所以伪代码可能如下所示:
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();
}
}
再说一次,它只是伪代码,所以我假设这就是它的工作原理。我没有测试语法,但我认为它很接近。
我希望这有帮助。祝你好运!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)