如何直接从浏览器使用JavaScript上传文本字符串到Windows Azure的Blob [英] How to upload a text string directly to Windows Azure Blob from the browser using javascript

查看:200
本文介绍了如何直接从浏览器使用JavaScript上传文本字符串到Windows Azure的Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Web浏览器上传text / html的字符串作为Azure的BLOB直接向Azure存储(无需首先直通Azure的VM / web服务器)使用浏览器端的JavaScript。从我的研究,我明白,人们可以使用Azure的REST API +共享访问签名从Silverlight客户端或直通的MVC 3视图实现这一目标。 (这里是链接,使用Silverlight / MVC3控制:的http://$c$c.msdn.microsoft.com/silverlight/Silverlight-Azure-Blob-3b773e26#content).我还发现上传库使用服务器端JavaScript和Node.js的 https://github.com/ jpgarcia / WAZ存储-JS

I would like to upload from a web browser a text/html string as an Azure blob directly to Azure storage (without first going thru the Azure VM/webserver) using browser side javascript. From my research, I understand that one can use Azure REST API + Shared Access Signatures to achieve this from a Silverlight client or thru an MVC 3 view. ( here is the link for controls using SilverLight/MVC3 : http://code.msdn.microsoft.com/silverlight/Silverlight-Azure-Blob-3b773e26#content). I also found a library for uploading using server side javascript with Node.JS https://github.com/jpgarcia/waz-storage-js .

我的问题是如何将一个上载的文本字符串只使用浏览器端的Azure的BLOB JavaScript和HTML和SAS(不使用Silverlight或MVC)等直接做天青足不出户直通的Web服务器?一个人怎么会字符串值传递给其余的Azure API调用(它会接受一个JSON字符串?)?我看了看MSDN REST API的例子,但它不是我清楚你将如何传递的文本字符串上传。任何人都可以帮助呢?先谢谢了。

My question is how would one upload a text string to an Azure blob using only browser side javascript and html and SAS (without using Silverlight or MVC) and do so directly to Azure without going thru the web server? How would one pass the string value to the Azure rest api call ( would it accept a JSON string?) ? I looked at the MSDN REST api examples but it was not clear to me how you would pass a text string to be uploaded. Can anyone help with this? Thanks in advance.

推荐答案

我不认为这是可以做到。除非网页是从同一个Blob存储域承载,这将是一个跨域调用,这是不允许的(除非CORS标头设置,他们不是为Blob存储)。

I don't think this can be done. Unless the web page is being hosted from the same blob storage domain, this would be a cross-domain call, which isn't allowed (unless CORS headers are set, which they aren't for blob storage).

另外,上传到一个blob需要HTTP PUT请求,我相信大多数的浏览器只允许POST和GET。

In addition, uploading to a blob requires an HTTP PUT request, and I believe most browsers only allow POST and GET.

更新

请参阅下面的评论,但它看起来像有些浏览器允许PUT请求。如前所述,同源策略可以从同一个Blob存储帐户中,原来的页面被击败。在这种情况下,code会是这个样子(使用jQuery):

See comments below, but it looks like some browsers do allow PUT requests. As noted, the same-origin policy can be defeated by serving the original page from the same blob storage account. In that case, the code would look something like this (using jQuery):

$.ajax({
    url: url,
    type: 'PUT',
    data: 'Hello, World!',
    headers: {'Content-Type': 'text/html'}
}).success(function () {
    console.log('Saved successfully.');
});

这篇关于如何直接从浏览器使用JavaScript上传文本字符串到Windows Azure的Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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