【发布时间】:2019-06-07 23:28:35
【问题描述】:
我正在编写https://scotch.io/tutorials/how-to-handle-file-uploads-in-vue-2 上发布的 vue.js 教程我正在尝试修改上传网站以使用 Microsoft Azure 存储 blob。但是,在我修改了一个名为“file-upload.service.js”的文件后,我收到了 405 错误:资源不支持指定的 http 动词我检查了 CORS 设置: 允许的来源 * 允许的方法 检查所有 http 动词 允许的标题 * EXPOSED HEADERS 内容长度 最大年龄 84600
- 我改变了 const BASE_URL = 'http://localhost:3001';转至https://XXXXXXXXX.z4.web.core.windows.net/
- 更改了 const url =
${BASE_URL}/photos/upload;到 const url =${BASE_URL}/images; - 改行 img, { url:
${BASE_URL}/images/${img.id}})));到 img,{ url:${BASE_URL}/images/${img.id}/${sasToken}})));
这是原始代码: // 文件上传.service.js
import * as axios from 'axios';
const BASE_URL = 'http://localhost:3001';
function upload(formData) {
const url = `${BASE_URL}/photos/upload`;
return axios.post(url, formData)
// get data
.then(x => x.data)
// add url field
.then(x => x.map(img => Object.assign({},
img, { url: `${BASE_URL}/images/${img.id}` })));
}
export { upload }
这是更改后代码的样子:
const BASE_URL = 'https://XXXXXXXX.blob.core.windows.net';
const AccountKey = '?XXXXXXXXXXXXXXXXX'
function upload(formData) {
const uri = `${BASE_URL}/images `;
return axios.post(uri, formData)
// get data
.then(x => x.data)
// add url field
.then(x => x.map(img => Object.assign({},
img, { uri: `${BASE_URL}/images/${img.id}/${AccountKey}` })));
}
export { upload }
预期结果:图像将上传到存储 blob 实际结果:错误405:资源不支持指定的http动词
{
"data": "<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>UnsupportedHttpVerb</Code><Message>The resource doesn't support specified Http Verb.\nRequestId:4d9b12be-e01e-0060-759b-1dfd43000000\nTime:2019-06-08T01:46:25.1276517Z</Message></Error>",
"status": 405,
"statusText": "The resource doesn't support specified Http Verb.",
"headers": {
"content-length": "237",
"content-type": "application/xml"
},
"config": {
"url": "https://XXXXXXXXX.blob.core.windows.net/images ",
"method": "post",
"data": {},
"headers": {
"Accept": "application/json, text/plain, */*"
},
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1
},
"request": {}
}
【问题讨论】:
标签: azure vuejs2 axios azure-blob-storage