我想我明白错误传达了什么,但我不知道我做错了什么。我认为它与url模式不正确有关。但我检查过,模式应该是正确的。 React中的getSignedRequest方法调用ajax函数来执行http post,但是错误反弹回来说500服务器错误。如果有人可以协助指出错误,我会很感激。
Express - app.js:
app.use('/', index);
app.use('/users', users);
app.use('/api/upload', upload)
React - App.js
getSignedRequest(file){
var fileObject = { file : { type: file.type, size: file.size }}
console.log("File object to upload: " + JSON.stringify(fileObject));
jquery.ajax({
url: "/api/upload/image",
data: JSON.stringify(fileObject),
contentType: "applicaiton/json; charset=utf-8",
dataType: "json",
cache: false,
method: "POST",
success: function(data) {
console.log("Get data back" + JSON.stringify(data.data))
this.uploadFile( file, data.data.requestURL, data.data.imageURL );
}.bind(this),
error: function(xhr, status, err){
console.log("Error on getting signed request :", err);
}.bind(this)
});
}
router.js:
router.post('/image', function(req, res, next){
if( !req.body.file ){ res.json( generalResponse( null, 2 )); return;
var file = req.body.file;
if( file.type == "image/png" || file.type == "image/jpeg" || file.type == "image/jpg"){
if( file.type > 2200000 ){
res.json( generalResponse( null, 4 )); return;
}
}else{
res.json( generalResponse( null, 4 )); return;
}
}
});