Android Question write/read file jpg/pdf on db sql with php

Uniko Sistemi srl

Active Member
Licensed User
Hi everyone, I would like to ask for advice on which approach to use.
I have a dbsql on a remote server on which I should save jpg/png and pdf files.
Currently for all the other information I write and read I use a php script (I use okhttpUtils2). What do you recommend me to do? Because I read that converting a jpg to base64 would be too heavy, as would uploading the jpg or pdf file directly to the db. Is there a way to make loading and reading these files easier?
Could postmultipart be the right way?
Thank you all
 

aeric

Expert
Licensed User
Longtime User
converting a jpg to base64 would be too heavy
The size of data maybe slightly bigger than the original file name. That's all. If that not a concern, then there should be no problem.

Could postmultipart be the right way?
Using multipart post is another option. Usually it creates a temporary file and you need to copy to another location. It can be write into a new file with information from the original filename and file extension, do image manipulation such as image resizing, and so on. The code may be slightly more complicated.

Either way is fine.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
You could dedicate a folder ( on server ) and insert the images.
For example, if you have an image like test.jpg, it is best to save the image in the dedicated server folder and the file name (test.jpg) in the db.
So that when you upload it you will have to read only the name from the db and take the photo from the folder giving the entire path where it is stored (https://xxxx.com/foto/test.jpg)
 
Upvote 0

Uniko Sistemi srl

Active Member
Licensed User
The size of data maybe slightly bigger than the original file name. That's all. If that not a concern, then there should be no problem.


Using multipart post is another option. Usually it creates a temporary file and you need to copy to another location. It can be write into a new file with information from the original filename and file extension, do image manipulation such as image resizing, and so on. The code may be slightly more complicated.

Either way is fine.
Thank you.
So I did a test, I convert my jpeg with Base64EncodeDecodeImage.Base64ImageToString. The only problem I encounter is that the string obtained is too large to put inside mysql. I'm definitely doing something wrong, but I don't understand how to make mysql accept it. Do I have to convert it some other way?
 
Upvote 0

Uniko Sistemi srl

Active Member
Licensed User
You could dedicate a folder ( on server ) and insert the images.
For example, if you have an image like test.jpg, it is best to save the image in the dedicated server folder and the file name (test.jpg) in the db.
So that when you upload it you will have to read only the name from the db and take the photo from the folder giving the entire path where it is stored (https://xxxx.com/foto/test.jpg)
Thank you. I would prefer a conversion for convenience, but I will try this too.
Thank you
 
Upvote 0
Top