我有一个简单的文件输入:
<input type="file" id="profilePhotoFileUpload" onchange="saveImage()">
然后saveImage()
函数如下所示:
function saveImage() {
var fileUploadControl = $("#profilePhotoFileUpload")[0];
if (fileUploadControl.files.length > 0) {
var file = fileUploadControl.files[0];
var name = "brand_logo"
var parseFile = new Parse.File(name, file);
var formData = new FormData();
formData.append('image', parseFile);
console.log("dATA: " + JSON.stringify(formData))
var request = new XMLHttpRequest();
request.open("POST", "/about");
request.send(formData);
}
}
在我的服务器端,我有这样的邮寄路线:
app.post('/about', function(req, res){
console.log("Data: " + JSON.stringify(req.body))
});
看起来数据开头是空的,在客户端和服务器端,它都是空数据,如下所示:
{}