Angularjs 对azure存储的$http put请求
我在尝试将图像上载到Azure存储帐户时遇到问题。问题在于config头是否正确地向服务器发出请求。我已经通过邮递员向自己发出请求来测试了这一点,工作起来很有魅力,但是当我试图用$http.put从角度来做这件事时,它给了我一个错误 400(身份验证信息的格式不正确。请检查授权标头的值。) 这是我的javascript函数Angularjs 对azure存储的$http put请求,angularjs,azure,http-headers,azure-storage,Angularjs,Azure,Http Headers,Azure Storage,我在尝试将图像上载到Azure存储帐户时遇到问题。问题在于config头是否正确地向服务器发出请求。我已经通过邮递员向自己发出请求来测试了这一点,工作起来很有魅力,但是当我试图用$http.put从角度来做这件事时,它给了我一个错误 400(身份验证信息的格式不正确。请检查授权标头的值。) 这是我的javascript函数 uploadToAzure: function (urlToUpload, fileType, file) { var formattedUrl = urlToUpl
uploadToAzure: function (urlToUpload, fileType, file) {
var formattedUrl = urlToUpload.split('"')[1];
var fecha = new Date();
var config = {
headers:{}}
config.headers = {
'x-ms-blob-type': 'Blockblob',
'x-ms-blob-content-type': fileType,
'x-ms-date': fecha,
'x-ms-version': '2017-04-17',
//'Host': 'necesito1.blob.core.windows.net',
'Authorization_Token': 'SharedKey <myAccount>:<MyPublicAccessKey>'
};
return $http.put(urlToUpload, file._file, config);
uploadToAzure:function(urlToUpload、文件类型、文件){
var formattedUrl=urlToUpload.split(“”)[1];
var fecha=新日期();
变量配置={
标题:{}
config.headers={
“x-ms-blob-type”:“Blockblob”,
“x-ms-blob-content-type”:文件类型,
“x-ms-date”:fecha,
“x-ms-version”:“2017-04-17”,
//'Host':'necesito1.blob.core.windows.net',
“授权令牌”:“SharedKey:”
};
返回$http.put(urlToUpload,file.\u file,config);
我读过这些文章,在这些文章中我发现了如何正确配置我的标题
////
如果有帮助的话,我从邮递员那里得到这个标题
我是否遗漏了什么?如果有任何帮助,我们将不胜感激。授权标题的格式如下:
Authorization="[SharedKey|SharedKeyLite] <AccountName>:<Signature>"
Authorization=“[SharedKey | SharedKeyLite]
另一个选择是使用共享访问签名(SAS)
。请参阅。好的,所以我终于找到了答案。问题是我发布的javascript是错误的,不是配置,而是我设置标头的方式。
再挖一点,我发现用我当时的方式设置标题是行不通的
return $http.put(urlToUpload, file._file, config);
我最终覆盖了$httpProvider的拦截器服务
angular.module('yourAppName', ['yourInyectedModules']).config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push(function ($q) {
return {
'request': function (config) {
//Do your custom processing here
config.headers = {
'x-ms-blob-type': 'Blockblob'
};
return config;
},
'response': function (response) {
// same as above
return response;
}
};
});}]);
要考虑到,如果您这样做,您就是在为客户端发出的每个请求进行设置,因此您需要处理您的请求,以便仅为特定的请求进行设置
无需授权,因为我的变量“urlToUpload”(要求azure为我提供上传文件的授权url)中的授权url格式已经正确。该类型是自动继承的,因此无需设置
谢谢你的回复陈亚伦