I want to upload canvas image through formdata/multipart
. I have a canvas which generates
the image data with toDataURL(). I want to upload image data as formdata/multipart
with
Ajax post.
Here is the code ....
var dataUrl = canvas.toDataURL('image/png');
var multipart = new FormData();
multipart.append('user_id', userID);
multipart.append('password', pwd);
multipart.append('inputdata',image data here);
$.ajax({
type : 'POST',
// dataType: 'json',
url : serviceURL,
data : multipart,
cache : false,
processData : false,
contentType : false,
success : function(data) {
},
error : function(xhr, status, error) {
}
});
I know that one can not append the image data uri into FormData. So how can i append this?
Thanks
canvas.toBlob()
instead oftoDataURL
. You would then need to callmultipart.append('inputdata', canvas.toBlob(), "filename")
(notice the third argument; the filename will default to"blob"
if you don’t provide it). – Disobedience