Cloundinary'ye resim yüklemeye çalışıyorum, ancak sunucuyu tüm kökene izin verecek şekilde ayarlamış olmama rağmen cors ile ilgili durum kodu 500 ile ilgili bir hata oluştu.
Hata mesajı:
POST http://localhost:5000/my-route-upload 500 (Internal Server Error)
işte benim YAZI işlevim :
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")
}); }
Sunucu tarafında, Uygulamada aşağıdaki bloğu ekledim.JS
const cors = require('cors');
var app = express();
app.use(cors({
origin: "*",
})
);
Bu kodlar gerçekten işe yaradı ve orijini aşağıdaki gibi belirli bir kodla değiştirmeye çalıştım http://127.0.0.1:3001 (müşteri bağlantı noktam 3000). Sonra başka bir hata mesajı çıktı
Ağ / Üstbilgiler sekmesinde ilk hataya geri dön :
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
Neden işe yaramadı bilmiyorum. İstemci için create-react-app ve sunucu için Express generator kullanıyorum
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") }); }