我试图像上传到Cloundinary,但发生了一个错误地位代码500有关软虽然我已经设置的服务器,以便允许所有来源。
错误消息是:
POST http://localhost:5000/my-route-upload 500 (Internal Server Error)
这里是我的职务功能:
const cloudinaryUpload = (fileToUpload) => {
return axios.post(API_URL + '/cloudinary-upload', fileToUpload)
.then(res => console.log(res))
.catch(err => {
console.log(err)
console.log("cannot post")
}); }
在服务器方面,我不得不添加下面的方框中App.JS
const cors = require('cors');
var app = express();
app.use(cors({
origin: "*",
})
);
这些代码有没有执行,我试着修改原产地为特定的一种喜欢 http://127.0.0.1:3001 (我的客户口3000). 然后就出来了另一个错误信息
回到第一个错误,在标签网络/Headers:
Request URL: http://localhost:5000/cloudinary-upload
Request Method: POST
Status Code: 500
Referrer Policy: strict-origin-when-cross-origin
Access-Control-Allow-Origin: *
Host: localhost:5000
Origin: http://127.0.0.1:3000
我不知道为什么它不工作。 我用创造-反应-应对客户和快速生成的服务器
const cloudinaryUpload = (fileToUpload) => { return axios.post(API_URL + '/cloudinary-upload', fileToUpload, {headers: { 'content-type': 'application/json' }}) .then(res => res.data) .catch(err => { console.log(err) console.log("cannot post") }); }