Reputation: 349
I am getting my image object from canvas and converting it into blob and then to file in java script
var sendingData = new FormData();
var ctx = mainCanvas.getContext("2d");
console.log("canveas content =" + noofchildren.get(i));
ctx.drawImage(noofchildren.get(i), 0, 0, mainCanvas.width, mainCanvas.height);
var b64Data = mainCanvas.toDataURL("image/jpeg", 0.7).split(",")[1];
var byteCharacters = atob(b64Data);
var byteNumbers = new Array(byteCharacters.length);
for (var j = 0; j < byteCharacters.length; j++) {
byteNumbers[j] = byteCharacters.charCodeAt(j);
}
var byteArray = new Uint8Array(byteNumbers);
var blob = new Blob([byteArray], { type: contentType });
var file = new File([blob], "sample.JPG", { type: "image/jpeg" });
sendingData.append(nameOfTheImageFiles[i], file);
var ajaxRequest = $.ajax({
type: "POST",
url: "/api/" + email + "/imagesupload",
contentType: 'multipart/form-data',
processData: false,
data: sendingData
}).success(function (data) {
console.log(data);
$("#image-container").children().remove();
});
i am using ajax to post my file to nodejs server
and req.files is an empty object in nodejs
How to resolve?
In asp.net I am getting the file on post method
Upvotes: 1
Views: 15425
Reputation: 162
Looking at the documentation of FormData.append()
, you can see that you can only have a File
as value when you have specified the third filename
parameter. So try swapping the relevant line to the following
sendingData.append(nameOfTheImageFiles[i], file, "sample.JPG");
Upvotes: 3