使用 Javascript 将大文件上传到 Azure Blob [英] Upload Largefile to Azure Blob using Javascript

查看:54
本文介绍了使用 Javascript 将大文件上传到 Azure Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过几个将文件传输到服务器端然后上传到 Azure Blob 存储的示例.
但是我有几 GB 大小的文件.
有没有一种方法可以使用客户端脚本将文件直接上传到 Azure Blob 存储,而不是从服务器端上传以节省时间.

I have seen few examples where a file is transferred to server side and then uploaded to Azure Blob Storage.
But I have files with size in few GBs.
Is there a way I can upload a file directly to Azure Blob Storage using Client Side scripts instead of doing it from Server Side to save time.

推荐答案

更新我的答案,现在 Windows Azure 存储支持 CORS 并且 OP 没有接受任何答案:).

Updating my answer, now that CORS is supported in Windows Azure Storage and the OP has not accepted any answer :).

是的,可以将大文件直接从浏览器上传到 Windows Azure 存储.您可能会发现这些步骤很有用:

Yes, it is possible to upload large files directly from your browser to Windows Azure Storage. You may find these steps useful:

  1. 首先创建一个共享访问签名 URL (SAS),并在要上传文件的 Blob 容器上至少具有 Write 权限.由于您要上传大文件,我建议您将 SAS 到期时间保持足够长.

  1. First create a Shared Access Signature URL (SAS) with at least Write permission on the blob container in which you wish to upload the files. Since you're uploading large files, I would recommend keeping SAS expiry time to be long enough.

接下来在您的存储帐户上启用 CORS.如果您希望以编程方式执行此操作,您可能会发现这篇文章很有用:http://gauravmantri.com/2013/12/01/windows-azure-storage-and-cors-lets-have-some-fun/.如果你想使用一个工具,我公司已经发布了一个免费工具来做到这一点.您可以阅读有关此工具的更多信息并从此处下载:http://blog.cynapta.com/2013/12/cynapta-azure-cors-helper-free-tool-to-manage-cors-rules-for-windows-azure-blob-storage/.

Next enable CORS on your storage account. If you wish to do it programmatically, you may find this post useful: http://gauravmantri.com/2013/12/01/windows-azure-storage-and-cors-lets-have-some-fun/. If you want to use a tool, my company has released a Free tool to do just that. You can read more about this tool and download from here: http://blog.cynapta.com/2013/12/cynapta-azure-cors-helper-free-tool-to-manage-cors-rules-for-windows-azure-blob-storage/.

我写了一篇关于将非常大的文件上传到 blob 存储的博客文章,您可以在这里阅读:http://gauravmantri.com/2013/02/16/uploading-large-files-in-windows-azure-blob-storage-using-shared-access-signature-html-and-javascript/.在您的存储帐户上启用 CORS 后,博客中提到的代码应该可以正常工作.

I wrote a blog post some time back on uploading very large files into blob storage which you can read here: http://gauravmantri.com/2013/02/16/uploading-large-files-in-windows-azure-blob-storage-using-shared-access-signature-html-and-javascript/. Once CORS is enabled on your storage account, code mentioned in the blog should work just fine.

<删除>实际上有一种方法虽然有一些先决条件/警告.

  1. 由于 Blob 存储尚不支持 CORS,因此您的 HTML 和 JS 文件需要存在于同一个 Blob 存储帐户中.它们应该位于公共 blob 容器中.
  2. 由于您要上传大文件,因此需要将它们分成小于 4 MB 的块.HTML 5 有一个文件 API,可以将文件拆分为块,但并非所有浏览器都支持此功能.

这篇关于使用 Javascript 将大文件上传到 Azure Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆