Tuesday, 30 March 2021

Ionic Input file capture file or memory is saved on mobile

So with my Ionic app I have some functionality to upload pictures. For taking or selecting these images I use two inputs:

 <input hidden="true" #fileCamera type="file" accept="image/*" capture="environment" (change)="uploadFile($event)">
 <input hidden="true" #fileGallery type="file" accept="image/*" (change)="uploadFile($event)">

When I run this code it works. With the #fileCamera it opens the camera and with the #fileGallery it opens the gallery.

But when I check my data from my android settings the data size keeps on increasing, when I use the fileinput with the capture="environment", so the one where it opens the camera. The size is increasing by approximately 2.4 MB so the size of a taken picture.

And when I use the other input (the gallery) it doesn't increase the size.

So I guess the pictures that are taken through the input and the app are getting saved somewhere, but I can't find them anywhere on my phone.

I don't know if it's a Ionic specific thing, but I can't find a solution. Is there some way to delete the file/image that is taken through the input?

This is my code which handles the file input:

    this.uploading = true;

    const eventObj: MSInputMethodContext = event as MSInputMethodContext;
    const target: HTMLInputElement = eventObj.target as HTMLInputElement;
    const file: File = target.files[0];

    this.media.uploadImageFile(file).then((attachment: Attachment) => {
      this.attachments.push(attachment);
    }).catch(() => this.translate.get('MESSAGES.ERROR').subscribe(msg => this.showToast(msg, 'danger')))
      .finally(() => this.uploading = false);


from Ionic Input file capture file or memory is saved on mobile

No comments:

Post a Comment