gpt4 book ai didi

azure - 错误 405 : The resource doesn't support specified http verb

转载 作者:行者123 更新时间:2023-12-03 04:49:39 26 4
gpt4 key购买 nike

我正在编写 vue.js 教程,发布于 https://scotch.io/tutorials/how-to-handle-file-uploads-in-vue-2我正在尝试修改上传网站以使用 Microsoft Azure 存储 blob。但是,在修改名为“file-upload.service.js”的文件后,我收到 405 错误:该资源不支持指定的 http 动词 我检查了 CORS 设置:允许的来源 *允许的方法 所有 http 动词都会被检查允许的 header *暴露的 header 内容长度最大年龄84600

  1. 我更改了 const BASE_URL = ' http://localhost:3001 ';线路至 https://XXXXXXXXX.z4.web.core.windows.net/
  2. 更改了 const url = ${BASE_URL}/photos/upload;到 const url = ${BASE_URL}/images;
  3. 更改了行 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": {}
}

最佳答案

您收到此错误的原因是上传 Blob 的 HTTP 方法是 PUT 而不是 POST: https://learn.microsoft.com/en-us/rest/api/storageservices/put-blob .

关于azure - 错误 405 : The resource doesn't support specified http verb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56502212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com