I wanna post the file with AJAX.
My JQuery code is:
$.ajax({
type: 'POST',
url: '/uploadPhoto',
data: $('#fileUp').attr('files'),
cache: false,
//contentType: 'multipart/form-data', //removed
processData: false,
dataType: "text",
success: function(data){
alert(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log(XMLHttpRequest.status);
console.log(XMLHttpRequest.readyState);
console.log(textStatus);
}
});
When I was post like this, the Nodejs's console show"[Error: Multipart: Boundary not found]".
What's the problem? How can I fix it? Anybody help~~~
See this StackOverflow post on how to make multipart uploads with jQuery.
var img=document.getElementById("input-img");
var video=document.getElementById("input-video-id-fv41");
var formdata = new FormData();
formdata.append('img',img.files[0]);
formdata.append('video',video.files[0]);
Most helpful comment
See this StackOverflow post on how to make multipart uploads with jQuery.