【问题标题】:Error 405: The resource doesn't support specified http verb错误 405:资源不支持指定的 http 动词
【发布时间】: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

  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": {}
}

【问题讨论】:

    标签: azure vuejs2 axios azure-blob-storage


    【解决方案1】:

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

    【讨论】:

    • 好的,所以我设置了一个 put 请求,然后设置了一个请求标头?顺便说一句,谢谢。
    • 是的。您应该使用 axios.put 而不是 axios.post。我相信您需要的唯一标头是 blob 类型。
    • 我已将返回行更改为: return axios.put(uri, formData,{headers:{"x-ms-blob-content-type":Image.id}}) 。但是,我现在收到 405 错误:指定的资源不存在。我记得有时可以在 blob 本身中设置一些权限,但我想我最好与你核实一下。
    • 您有“图像”blob 容器吗?您还需要“x-ms-blob-type”请求标头。
    猜你喜欢
    • 2018-05-30
    • 2014-12-16
    • 1970-01-01
    • 2016-11-18
    • 2014-06-23
    • 2017-05-24
    • 2021-04-27
    • 2017-12-15
    • 2015-03-11
    相关资源
    最近更新 更多