上传图片文件从JS蔚蓝的Blob存储 [英] Upload an image file to azure blob storage from js

查看:1114
本文介绍了上传图片文件从JS蔚蓝的Blob存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个html页面天青Blob存储上传的图像文件。到目前为止,我已经写了一个Web服务来为我的blob容器创建一个SAS。从这个我已经创建的格式为一滴地址/容器名称/一滴名的URI? SAS。我有我的HTML页面上上传控件。

I'm trying to upload an image file from an html page to azure blob storage. So far I have written a web service to create an SAS for my blob container. From this I have created a uri of the format "blob address" / "container name" / "blob name" ? "sas". I have an upload control on my html page.

我已经然后试图用下面的code上传的文件:

I have then tried to upload the file using the following code:

var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.addEventListener("abort", uploadCanceled, false);
xhr.open("PUT", blobPath);
xhr.send(upFile.files[0]);

其中blobPath是URI如上和upFile是我的HTML上传控件。

where blobPath is the uri as above and upFile is my html upload control.

当我尝试上传uploadFailed程序被触发的文件。所以:
这是做的正确方法?
我如何圈套上传回来,这样我可以看到什么错误?误差

When I try to upload a file the uploadFailed routine is triggered. So: Is this the right way to do this? How do I trap the error returned by the upload so that I can see what is going wrong?

我的SAS样子:SR = C放大器; SI = mypolicy&安培; SIG = onZTE4buyh3JEQT3%2B4cJ6uwnWX7LUh7fYQH2wKsRuCg%3D

My sas looks like: "sr=c&si=mypolicy&sig=onZTE4buyh3JEQT3%2B4cJ6uwnWX7LUh7fYQH2wKsRuCg%3D"

任何帮助AP preciated,谢谢。

Any help appreciated, thanks.

推荐答案

我现在已经发现,对于这个问题的解决方案。我现在上传的作品如下:

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


  • 我读文件作为DataURL成的FileReader

  • 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

在整个文件已发送了我所说的另一个Web服务,
胶水切片一起回来并把结果到字节数组

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

最后文件从本地存储转移到Blob存储

Finally the file is transferred from local storage into blob storage

请参阅code。在

从HTML文件上传到Azure

这篇关于上传图片文件从JS蔚蓝的Blob存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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