[SOLVED] Cordova camera to base64 in memory or file system


#1

In my app, a user could take or upload 1 to 5 photos.

To achieve that process I use the cordova camera plugin. I also, before uploading them to my server (S3), allow the user to crop them within the help of cropperjs.

Right now I implemented everything purely based on base64 images which I save in a service till the upload to the server is done.

I read (somewhere) that it is quite a bad practice to use base64 with camera because there is a risk of reaching an out of memory exception. Is that right? Any thought on that?

And if I should rather use local files, what should I rather use when I configure the cordova camera plugin, rather NATIVE_URI or FILE_URI? Any good post or tutorial about that subject?

***** Update: So I tried NATIVE_URI and FILE_URI and seems that FILE_URI works better in my case. I also have the feeling that the quality of the pictures are better with FILE_URI

Still, after having a FILE_URI, I use cropper, which gonna give me back a base64 URI.

So my question, is it safe to keep in my service memory up to 5 images as base64 or is there an out of memory possibility? If yes, what should I do then, save the images to a tmp file on the device till I upload the photos to my server?


#2

you dont need external library to crop image… add allowEdit:true in cameraoptions will do…and for prevent the out of memory issues i think you can use filetransfer plugin to upload image to your server


#3

thx for your answer but doesn’t really answer my questions. I already have a library to crop my image (cropperjs, which I better like than the cordova allowEdit) and I don’t need a plugin to transfer my file (I have a S3 and the file transfer is already implemented).

My question is about the usage of the memory regarding the images and best practices. Is it safe to handle 5 images, till I upload them to my server , as base64 files in my app memory (“ram”) or should I better save them on the device (“rom”) ?


#4

Summarized I ended up implementing following scenario:

  • Access photo or take photo with the cordova camera plugin using FILE_URI
  • Using cropper in a view to let the user crop is image
  • When the user crop is image and confirm his selection, I get the result of cropper as byte array and then user the cordova plugin file to write this img locally
  • Finally, when the user is done and send his info to the servers, I read the local files, transform them as blob and send them to my S3

In this scenario I use the cache directory as local directory and I also remove the directory and all children data when the user initialize a new wizard

Using this scenario, even I’m still not sure it was needed, the memory of the app during my wizard gonna be reduced even if the images are big


#5

Hello , can you share the code , Thanks :slight_smile:


#6

Unfortunately no. But if you’ve got specific questions for sure I could try to help.


#7

I have done most of the steps , Now i need to encrypt the images by using $cordovasqlite , then find a way to send it to a server through file transfer plugin


#8

Unfortunately, I don’t use cordovasqlite or the file transfer plugin, I won’t be that much an help here :frowning: