简体   繁体   English

使用 Javascript 将大文件上传到 Azure Blob

[英]Upload Largefile to Azure Blob using Javascript

I have seen few examples where a file is transferred to server side and then uploaded to Azure Blob Storage.我见过几个将文件传输到服务器端然后上传到 Azure Blob 存储的示例。
But I have files with size in few GBs.但是我有几 GB 大小的文件。
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.有没有一种方法可以使用客户端脚本将文件直接上传到 Azure Blob 存储,而不是从服务器端上传以节省时间。

Updating my answer, now that CORS is supported in Windows Azure Storage and the OP has not accepted any answer :).更新我的答案,现在 Windows Azure 存储支持 CORS 并且 OP 没有接受任何答案:)。

Yes, it is possible to upload large files directly from your browser to Windows Azure Storage.是的,可以将大文件直接从浏览器上传到 Windows Azure 存储。 You may find these steps useful:您可能会发现这些步骤很有用:

  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.首先创建一个Shared Access Signature URL (SAS) ,至少对要在其中上传文件的 blob 容器具有Write权限。 Since you're uploading large files, I would recommend keeping SAS expiry time to be long enough.由于您要上传大文件,我建议您将 SAS 到期时间保持足够长。

  2. Next enable CORS on your storage account.接下来在您的存储帐户上启用 CORS。 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/ .如果您希望以编程方式进行,您可能会发现这篇文章很有用: 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.如果你想使用一个工具,我公司已经发布了一个Free工具来做到这一点。 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/ .您可以阅读有关此工具的更多信息并从此处下载: http : //blog.cynapta.com/2013/12/cynapta-azure-cors-helper-free-tool-to-manage-cors-rules-for-windows-天蓝色斑点存储/

  3. 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/ .我写了一篇关于将非常大的文件上传到 blob 存储的博客文章,您可以在这里阅读: 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.在您的存储帐户上启用 CORS 后,博客中提到的代码应该可以正常工作。

Actually there's a way though there are some preconditions/caveats.实际上有一种方法,尽管有一些先决条件/警告。
  1. Because CORS is not supported in Blob Storage just yet, your HTML and JS file need to be present in same blob storage account.由于 Blob 存储尚不支持 CORS,因此您的 HTML 和 JS 文件需要存在于同一个 Blob 存储帐户中。 They should be in a public blob container.它们应该位于公共 blob 容器中。
  2. Since you're uploading large files, they would need to be split into chunks less than 4 MB in size.由于您要上传大文件,因此需要将它们分成小于 4 MB 的块。 HTML 5 has a File API which can split the file into chunks but not all browsers support this feature. HTML 5 有一个文件 API,可以将文件分成块,但并非所有浏览器都支持此功能。
I wrote a blog post some time ago about uploading large files using pure JavaScript and Shared Access Signature.前段时间我写了一篇关于使用纯 JavaScript 和共享访问签名上传大文件的博客文章。 You can read that post here: http://gauravmantri.com/2013/02/16/uploading-large-files-in-windows-azure-blob-storage-using-shared-access-signature-html-and-javascript.您可以在此处阅读该帖子:http://gauravmantri.com/2013/02/16/uploading-large-files-in-windows-azure-blob-storage-using-shared-access-signature-html-and-javascript .

Azure released Storage JavaScript client library for browsers. Azure发布了用于浏览器的Storage JavaScript客户端库。 https://azure.microsoft.com/en-us/blog/new-azure-storage-javascript-client-library-for-browsers-preview/ https://azure.microsoft.com/zh-CN/blog/new-azure-storage-javascript-client-library-for-browsers-preview/

Guide and samples are here: https://dmrelease.blob.core.windows.net/azurestoragejssample/samples/sample-blob.html 指南和示例在这里: https : //dmrelease.blob.core.windows.net/azurestoragejssample/samples/sample-blob.html

Also a simple demo here to upload a blob to a container using SAS token. 这也是一个使用SAS令牌将Blob上传到容器的简单演示。 https://authinazuread.azurewebsites.net/storage.html https://authinazuread.azurewebsites.net/storage.html

It's all client side javascript, so files are not transferred to server. 这些都是客户端javascript,因此文件不会传输到服务器。 It supports chunked upload and works well with large files. 它支持分块上传,并且可以很好地处理大型文件。

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

相关问题 使用 javascript 在 azure blob 上传中暂停和恢复选项 - Pausing and resuming option in azure blob upload using javascript 使用 UploadBrowserDataToBlockBlob 从 Javascript 上传时在 Azure Blob 上设置 ContentType - Set ContentType on Azure Blob on upload from Javascript using UploadBrowserDataToBlockBlob 如何使用JavaScript将图像上传到Azure Blob存储 - How to upload image to azure blob storage using javascript Javascript 使用 msgreader 的附件提取并上传到 Azure blob 存储 - Javascript using msgreader's attachment Extraction & upload to Azure blob storage 通过 javascript 上传票证上传到 Azure Blob - Upload to Azure Blob via javascript upload ticket 使用Javascript创建Azure Blob - Creating Azure Blob using Javascript 如何使用javascript从浏览器直接将文本字符串上传到Windows Azure Blob - How to upload a text string directly to Windows Azure Blob from the browser using javascript 在asp.net中使用javascript在Azure BLOB存储上载期间,如何压缩视频? - How can i compress video during upload on Azure BLOB storage using javascript in asp.net? 使用 Nodejs 中的 azure 函数将图像从 URL 上传到 azure blob - Upload Image to azure blob from a URL using azure functions in Nodejs 从客户端Javascript上传Azure存储块Blob - Azure Storage Block Blob upload from client side Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM