Hello, I'm developing in an application using angular 2. I use dropzone.js to upload files. The problem is this: When I load the files directly from dropzone to an array of files, as in the code below:
this.showUploadFileNotAllowed = false;
if (this.myDropzone.files.length !== 0) {
for (var i = 0; i < this.myDropzone.files.length; i++) {
if (this.myDropzone.files[i].size > 5242880) {
this.showUploadFileNotAllowed = true;
this.showUploadMaxSizeExceed = true;
}
}
for (var i = 0; i < this.myDropzone.files.length; i++) {
this.attachmentsArray.push({
filename: this.myDropzone.files[i].name,
content: this.myDropzone.files[i].dataURL.split('base64,')[1],
encoding: 'base64',
})
}
}
works perfectly (for image files). How can you see the response of the post:
However,sinceIneedtosendotherfileformats,Idecidedtousethefilereaderasinthefollowingmethods:
publicgetBase64(file,i){varreader=newFileReader();reader.readAsDataURL(file);reader.onload=(el=>{this.loadAttachments(file.name,reader.result.split('base64,')[1]);});reader.onerror=function(error){console.log('Error:',error);};}publicloadAttachments(name,content){console.log(content);this.attachmentsArray.push({filename:name,content:content,encoding:'base64',})}
SoinsteadofdoingthatdirectdropzonepushImakethegetBase64methodcall.Butthiswaythearray"attachments" in the post goes empty. Could anyone give a light of what could be the problem?