我有一个通过 express 调用后端的 vue 应用程序。当我将图像添加到请求时,请求不会重定向到后端。但是,当我直接从 vue 应用程序调用后端时,没有 express,请求被正确处理。图像在途中以某种方式丢失。
Vue代码:
uploadImage(){
this.loadingImage = true
const url = "/person/"+localStorage.getItem("userUuid")+"/picture";
var config = {headers: {"Authorization": "Bearer "+localStorage.getItem("token")}};
const fd = new FormData();
fd.append('image', this.picture, this.picture.name)
this.$http.post(url, fd, config)
.then((response) => {
console.log(response)
this.loadingImage = false
//window.location.reload()
})
.catch((error) => {
console.log(error)
})
应用程序.js
const proxy = require('express-http-proxy');
const express = require('express')
const fileUpload = require('express-fileupload');
const app = express();
app.post('/person/:id/picture', proxy(config.backendURL, {
filter: function(req, res) {return checkBearer(req, res)}
}));