Should I store Bitmaps in SQLITE DB - android

Is it a good idea to store images retrieved from the web server via a web service in SQLITE DB. I am working on this android app that retrieves a lot of images from a web server and places them in a listview. And I would like to store the first 100 images in some storage area within an android device(That is after compressing them.) when a user first opens the app so that the app doesn't reload a fresh the next time the user opens the app . So, I am looking at SQLITE as one of my top storage options and I am not sure whether there could be a better way to doing this for the sake of improving the app performance. I have seen the question asked at Should i store images in SQLite database? and its answer, which a little fuzzy to me. Your opinion is highly appreciated. Thanks in advance.

Depends on the size of images - If the returned result of your query is going to be more than 1 MB (the binder limit) then you would have to store them as files and only store the URIs in the dbs.
For example you can look at the Contacts Provider - the thumbnails are stored in the db but the full images are not - only URI of the full image is part of the contacts database.

The question you linked too explains the best practise.
Generally, you should store the actual image files in the filesystem or memory card of the device.
Then your app can find references to them in your database
e.g.
SELECT avatar_image FROM profile WHERE user_id = 1; would return the local device file path of your stored image that can then be loaded into your ImageView.

Related

How to insert your own image into a SQLite table?

I have made a table with user info already stored in it. When the user registers with the id, all the details like username, course are retrieved from the table if the id matches. Now I want to add profile pictures in my user info table. Almost all tutorials on the internet are about saving a photo from your phone into that database and retrieving it. But i don't want that. I would like to add different image into the table for each user, i.e. it should be specific to the user. Now I know a BLOB datatype is used and the images should be converted to bytes. But I don't know where I should store the images, whether in my phone or in my res folder. Or maybe store it on the internet. I am confused.
I should mention that this isn't an ideal application, its just a model.
One of the most important factors to consider is the size of the images. If the size is likely to be in excess of say 200k then there is an increasing risk of there being issues not with storing the image in the database but retrieving the image.
Without writing your own alternative of CursorWindow then a CursorWindow (a buffer to hold a sub-group of the rows in a Cursor) is limited to 2M in size (in later versions at some it I believe it was 1M). If a picture is approaching 2MB there is no way that the picture can be retrieved (even without considering space for other columns).
As such, the generally recommended approach is to not store images but store a means of retrieving the image from a file store elsewhere (you've mentioned the res folder, which could be fine but you may need to consider the size of the APK), you could then store the file path in the database.
There's a more comprehensive answer that covers the above including storing small images in the DB and larger images elsewhere (assets folder) here
For anyone who has the same question like me, I found this tutorial to be the most easiest way to store images and retrieve it. It uses an external sqlite database to store images and info, and access it in the java page to display which i found quite easy.

How should I store profile photos database/server-side for an Android app?

I want users of my app to be able to view a gallery of profile photos on their phone but I'm not sure about the best way to store the gallery on the server? I'm using Postgres and a Java web service.
Should I store the images (or only a thumbnail) on the database or store only the paths and use a separate web server as I have read some people do? I wanted to make it as Android-based as possible so I wouldn't have to rely on having a web server to serve photos, but is there no way around it?
I have read about Postgres extensions to hold image files but I don't know if this is the most efficient way or not (I suspect it wouldn't be).
It really comes down to the size of the photos and how many of them you plan to be storing. Sometimes the database can be a viable option to store small thumbnail images, but generally this probably isn't the cheapest or most scalable solution but could avoid system complexity for a small project. For most projects I would go for file system/blob storage for images.
You should store both your full-size photos and thumbnails in the file system and store only paths in database. This would be more performance efficient.
You will probably need web server in order to protect who can see which photo.

Android - best way to handle downloaded image files

I am building an app that shows user's FB friends' location on a map with their profile pic as the map marker icon.
After downloading friends' pics, I stored them on ArrayList on a global application object and then show them on the map.
I've realized that I am spending a lot of heap memory for doing that.
I guess the right way to do it will be by storing them on the external storage, but I am not sure how to do it. Or maybe use SQLite database.
So my question is, what is the most efficient way to do that process? keep in mind that when a user's friend connect to the app, the app should show him on the map in real time.
Using ArrayList to store images does not scale very well, a better approach would be to store them in a database using Blob as described here:
How to save images into Database
Another way of doing this if you're not too comfortable with object persistance, is saving your images to filesystem and simply storing in a database table the pathnames to the images, so you can retrieve them when needed.

Profile images save as blob vs in filesystem

So I've got a unique system going on which is spread across 2 apps and 1 website. All 3 components of the system will share the same data source now each user has 1 and only 1 image to upload which will be their profile image. I'm debating if I should store them in the file system or the database the trade here are equal in my eyes. Storing them in the file system I'll have to retrieve them in 3 different systems from one server hassle.. on the other hand storing them in the DB could potentially make the DB slow.
One thing I see happening here is what if I make an images table and not back it up and just have all images reference an image in the images table. Worst thing that can happen is I'll lose all images.. xD which isn't really significant
I'm using windows azure to host my database
my website will run asp.net on windows azure and I'm using azure mobile services to serve apps
Since the same image is used by 3 applications, I would recommend using a central place for storing the image instead of storing it locally in the application. The advantage you will get is that if a user updates the image from any application, changes will be reflected in other applications as well without worrying about the synchronization hassles.
However instead of using a database table for storing images, use Windows Azure Blob Storage. It is meant for that purpose only. Furthermore your data is replicated 3 times within same data center and optionally you could geo-replicate the data for additional redundancy. With blob storage you don't have to worry about backups as well.

storing image in MySQL to display in Android listview advice

I need some advice. I am doing a grocery list app on the android platform. I am planning to add product images and name to the listview. I am using MySQL and php(using XAMPP localhost) to display the data. So far i was successful with the text display using AndroidHive's connect tutorial.
My question is how should i store the images:
Upload the images to the database using datatype BLOPB
or
Transfer the image to the localhost(htdocs) folder then store directory path(using varchar datatype) [not sure if its possible but I have done something similar in asp.net]
I have seen some example here but not too sure which would be easier for me(beginner level). Thanks!!
Its better if you store images to localhost and use the associated localtion in db.
Because, converting image files and then storing it database would be difficult.
On the other half, it would affect your DB size a lot.
Storing data at localhost would be effective as the size of local disk is not a problem. Moreover, you will have access to image files directly.

Categories

Resources