하려고 해요 이미지를 업로드하 Cloundinary,그러나 오류가 발생한 경우 상태코드가 500 에 관한 cors 지만 나는 설정을 허용하도록 서버의 모든 기원합니다.
오류 메시지는 다음과 같습니다.
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). 그런 다음 그것이 나온 다른 오류 메시지
다시 처음에 오류 탭 네트워크/헤더:
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") }); }