When I add the compressor within the jQuery.each and append the compressed image to data (FormData) it does not work. The code is okay and but it seems i am appending a empty result. The server API does not detect any files in the form post before it did. The compressor seems to be successful. I get the log message.
Original code:
var data = new FormData(); jQuery.each(jQuery('#imgupload')[0].files, function (i, file) { data.append('file-' + i, file); }); $.ajax({ data: data,
Change code.
var data = new FormData(); jQuery.each(jQuery('#imgupload')[0].files, function (i, file) { var compressor = new Compressor(file, { quality: 0.8, success: function (result) { console.log('Image compressed'); data.append('file-' + i, file); } }); $.ajax({ data: data,
When I add the compressor within the jQuery.each and append the compressed image to data (FormData) it does not work. The code is okay and but it seems i am appending a empty result. The server API does not detect any files in the form post before it did. The compressor seems to be successful. I get the log message.
Original code:
var data = new FormData(); jQuery.each(jQuery('#imgupload')[0].files, function (i, file) { data.append('file-' + i, file); }); $.ajax({ data: data,Change code.
var data = new FormData(); jQuery.each(jQuery('#imgupload')[0].files, function (i, file) { var compressor = new Compressor(file, { quality: 0.8, success: function (result) { console.log('Image compressed'); data.append('file-' + i, file); } }); $.ajax({ data: data,