I am using ngx-image-cropper to crop an image in my angular app. I use the Output property returning 'File' which is (imageCroppedFile) to be able to grab the cropped image. I need the cropped image to have a file name, so that I can iterate through the files on the back end using the name attribute, while it is by default undefined. How can I give it a name? I tried the following: On the FormData,
var formData:any = new FormData();
console.log('The number of files is '+files.length);//Logs the number of files is 1
for(var i=0; i<files.length;i++) {
formData.append("uploads[]", files[i].name, 'image'+i);
console.log('File name '+ i + ' ' +files[i].name);//Logs File name 0 undefined
}
and on the method triggered by the cropping
imageCroppedFile(image: File) {
this.filesToUpload = [];
console.log('imageCroppedFile method '+image.name+ ' size is '+image.size);// Logs imageCroppedFile method undefined size is 380284
this.filesToUpload[0]=image;
console.log('The filesToUpload is '+this.filesToUpload[0].name);// Logs The filesToUpload is undefined
}
The uploader works without the cropper.
cast your file into blob, and you can name your blob by yourself
Reference : https://github.com/Mawi137/ngx-image-cropper/issues/91#issuecomment-422252629