Upload an image file to azure blob storage from js

*爱你&永不变心* 提交于 2019-12-05 18:37:37

This is certainly the right way however there're a few things:

  1. You have to include x-ms-blob-type request header in your request and it's value should be BlockBlob.
  2. Also please realize that for this to work, you would need to host your HTML page in the same storage account because CORS is not supported in Azure Blob Storage as of today. So if your html page is hosted in some other domain, you would get error because of CORS.

You may find these blog posts useful for uploading blobs using SAS and AJAX:

http://coderead.wordpress.com/2012/11/21/uploading-files-directly-to-blob-storage-from-the-browser/

http://gauravmantri.com/2013/02/16/uploading-large-files-in-windows-azure-blob-storage-using-shared-access-signature-html-and-javascript/

Rachel Edge

I have now found a solution that works for this problem. My upload now works as follows:

  • I read the file as a DataURL into a FileReader

  • I slice the returned string up and send each slice up to the server where it is stored in a session variable

  • Once the whole file has been sent up I call another web service which glues the slices back together and turns the result into a byte array

  • The byte array is then stored as a file in local storage in azure

  • Finally the file is transferred from local storage into blob storage

See code at:

Upload files from html to azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!