错误405:资源不支持指定的http动词

时间:2019-06-07 23:28:35

标签: azure vuejs2 axios azure-storage-blobs

我正在研究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动词 允许的标题* 暴露的标题内容长度 最高年龄84600

  1. 我更改了const BASE_URL ='http://localhost:3001';行到https://XXXXXXXXX.z4.web.core.windows.net/
  2. 已更改的常量网址= ${BASE_URL}/photos/upload;改为const url = ${BASE_URL}/images;
  3. 更改了img行,{url:${BASE_URL}/images/${img.id}}))));到img,{网址:${BASE_URL}/images/${img.id}/${sasToken}}))));

这是原始代码:     // file-upload.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": {}
}

1 个答案:

答案 0 :(得分:0)

出现此错误的原因是,用于上传Blob的HTTP方法是PUT,而不是POSThttps://docs.microsoft.com/en-us/rest/api/storageservices/put-blob