I developed an image-cropper, which generates a base64 and after that creates an image file. But I have no idea how to insert image data into an entry to generate a FileList. Can someone help me?
Asked
Active
Viewed 299 times
1 Answers
0
If i understand what you need is an input file to pass the event to image-cropper.
PS : the event have the files data.
Example : HTML :
<input id="input-files" type="file" (change)="onImageFileChanged($event)" accept="image/*" />
<image-cropper *ngIf="imageChangedEvent" [imageChangedEvent]="imageChangedEvent"></image-cropper>
TS:
imageChangedEvent: any = '';
onImageFileChanged(event: any) {
this.imageChangedEvent = event;
}
Now inside this.imageChangedEvent
a list of images that you have selected.
If you want to put back your files to input file then try this :
const data = new ClipboardEvent('').clipboardData || new DataTransfer();
data.items.add(new File(['foo'], 'image.png'));
// replace new File(['foo'], 'image.png') with your file
document.getElementById("input-files").files = data.files;
Source : stackoverflow-set-file-objects

Oussail
- 2,200
- 11
- 24
-
I already have already do what you told me, but I need to throw the new value generated by the image-cropper to the input. To recover To retrieve later with *NativeElement.files* – Dougwn Feb 20 '20 at 15:48
-
I have added the answer of what you need now. – Oussail Feb 20 '20 at 15:57
-
Thanks buddy, you help me so much! – Dougwn Feb 20 '20 at 16:19
-
Please note that at the moment this is only supported on Firefox and Chrome (and Edgium). – Rik Feb 21 '20 at 06:53