Android Question What is the best practice for taking pictures, saving it, and uploading it to a server if I have full control?

Daica

Active Member
Licensed User
My current implementation is this:

1. User takes a photo in the app
2. Photo is converted to base64, stored inside local SQLite file.
3. When user is done, they press the upload button
4. The app will save all the images taken to the user's photo gallery
5. I start a service that will loop through the SQLite file and create a JSON for each row and then use okhttp to send the JSON data to the server
6. The server is a PHP server, it receives the JSON and converts base64 back to an image
7. The PHP server will use other data in the JSON to manipulate the image if needed and then save to a folder on the server.

This has worked fine for me for a while now but there has been some issues, like the app crashing because the cursor is too large (over 2MB).
I found this post here that explains and give a great fix: https://www.b4x.com/android/forum/t...ry-to-avoid-sqlite-errors.142048/#post-900231

However, it seems like storing 100+ images as base64 is not the way to go.

If I have full control over the server and the app, what would be the best practices storing and uploading the images?
 

drgottjr

Expert
Licensed User
Longtime User
images (except, perhaps, tiny thumbnails) should not be stored in the db.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Just guessing, as we don't know your project.
I would upload the image to server via FTP.
In the DB I would just save the image filename and the JSON to manipulate it.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
images (except, perhaps, tiny thumbnails) should not be stored in the db.

I agree: don't shove the image into the database. (*)

An adjacent solution could be to save the image with a temporary, unique filename and then storing that filename in the database. It might not be needed in your situation, but perhaps it can also make things easier if you have that info in there. (You could, for instance, have a column with a timestamp "uploaded_at" while the actual image is deleted to preserve space. Like I said - it depends on your situation and requirements.)

The rest of your solution looks solid to me.

(*) I am not certain, but I think you need to execute the vacuum command now and then on the database if you store your images in there so it won't keep growing even though you delete the images after a while. If not, the database could balloon and cause issues down the line, something that very well could be painful to debug because it only happens to some users, and after seemingly random time.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…