Hello i nead to send a blob to a server to specific folder. My problem is when i creating blob and send it Ajax as form data object it cause memory leak. How i can free memory after or before Ajax call and how to make this asynchronous... Please help
This is my code:
button1.addEventListener('click', event =>{
var dataURI = output.canvas.toDataURL();
var byteString = atob(dataURI.split(',')[1]);
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
var arrayBuffer = new ArrayBuffer(byteString.length);
var _ia = new Uint8Array(arrayBuffer);
for (var i = 0; i < byteString.length; i++) {
_ia[i] = byteString.charCodeAt(i);
}
var dataView = new DataView(arrayBuffer);
var blob = new Blob([dataView], { type: mimeString });
console.log(blob);
var formData = new FormData(); // create a new form data
formData.append("image", blob, "image.png");
// other form objects //
$.ajax({
type: 'POST',
url: '/app',
data: formData,
processData: false,
contentType: false
})
.done(async function() {
await sleep(10000);
})
});