Save image in MySQL and read it in Android

1

Well, I have the following problem:

  • I have a web application with which I want to be able to keep records of 2 tables, which must contain images. I want to save those records (with everything and images) in a MySQL server so that later I can read those records and show their images in an Android application.

The problem is that I must be able to consult the registers even if the Android device I am using does not have an Internet connection, that is, I have to clone the MySQL database in a SQLite database every time the device is connected to it. internet.

Now, as I understand the first thing I should do is create the MySQL server, then connect it to the web app and save the records there, my first question is: What type of data should I use to save the images? So once you clone the database from MySQL to SQLite can read the images in the Android app?

My second question, I do not have the slightest idea of how to clone a MySQL database to SQLite, Could you provide me with an example?

My third question, (which should have been the first): Between the 2 tables I will have an average of 100 to 150 records, that is 150 images (approximately 960x640) SQLite can support saving that number of images?

I hope you can help me, thanks in advance.

    
asked by Eduardo Carrillo 18.08.2016 в 02:10
source

1 answer

2

The type of data to save the images on your server is of the BLOB type, but here you have several problems:

  • The database grows a lot in size
  • It is not possible to create a service / API in JSON to exchange information since there is no support for binaries, only string.

What is normally done is that in your server database you save the link pointing to your image, and it would be as simple text of type VARCHAR (depending on your database) and it would be impeccable with an API in JSON to exchange information with your Android devices. Now, if you want to save the image in the database and you can not use a reference link for your images, you only need to transform your image to base64 so that it looks like String but with the cost that your image would have bad quality and the exchange of information would be very slow.

To "clone" your database you have two options: make a direct connection with the server which is a very bad idea (nobody does it) since you must have the user / pass accesses inside the Android application and it is very dangerous, and the second option is through data exchange through a service that you must build on the server side (API / JSON) to be consumed by your devices.

    
answered by 18.08.2016 в 21:56