0

I am trying to develop an Android app that will connect to a remote SQL database using PHP. I have images stored in the remote SQL database as BLOB. (For example a table with student id, student name, student image) I will need to save this data onto my Android database.

I have read that using JSON is a good way but is unable to find any good samples on saving the image blob from PHP to the Android database. I would appreciate if you can guide me on both the server side and the client side. Thanks.

1 Answer 1

3

The reason your not finding any examples using blob is because storing images as a blog is highly warned against. I had the exact same problem as you and eventually decided to switch over and store the images in the file system and only a path in the db. This makes it much easier to get the images over to android.

Its an especially bad idea to store images as blob on android for several reasons, the biggest that a object can never excede 1 meg. So if your trying to create a DB cursor to display your items in a list view then you will be limited to 1-10 items before your app crashes. I speak from experience.

If you want more info, leave a comment. gotta run to class for now.

Sign up to request clarification or add additional context in comments.

7 Comments

I see. If it is in a file system, I will have to get the images one by one right? I am trying to see if it is possible to retrieve all the images over a 1 time connection.
Why should storing binary data in blobs be warned against?
Thanks for your comments. What I intend to do is to have an update button where it downloads all the required images in a one-time connection. I intend to just display a single object which will change according to the user's input.
@Oliver Hanappi coz it's android , coz it's sqlite ... Better idea is storing url to image in db with path to local storage copy of this image
@ZXingIT no you can still download them all at one time. What I would do is get a json encoded array of all the path names. Then I would create a HttpURLConnection with the url of each image and store it somewhere on the sd. I can make an edit to my answer if you would like to see how i did it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.