I need to store images in Firebase - storage and download them to every connected devices as soon as the image is added to the storage. However, what is the efficient way to achieve this?
Should a Firebase-job-dispatcher be used for this purpose?
Or is there any listener/methods that fetches the images and sync the storage?
The Download Files on Android docs from Firebase does explain various methods to retrieve the files such as : by bytes, via URL, FirebaseUI. However from the app perspective, how do I listen for any change in the storage(insertion/deletion of an image) and thereby performing operations in Firebase? If a new image is inserted, download it, or if its deleted, remove from app memory.
Any info regarding this would be much appreciated.
I'd suggest using Firebase database and having image url properties pointing to your images. This info will get synced back to client and you can then use something like Picasso to render the image (using the url).
Related
I would like to create an app where I could save text, image and audio notes to an offline database(without internet connection) and then show them in a list-like layout. Wouldnt like to save the files to internal storage directly.
Its my first time creating mobile app so I need help in choosing the right database for such use case. Any suggestions?
I think you may be confusing some terms.
While you can put all sorts of media in a database. Sometimes it not the most practical solution. It sounds like you might be thinking of file storage, not a database.
Further more, the files have to live somewhere, if not on a external server/database, than they will have to reside locally on the device. Your app will not have a local database service running just so that it can store media files. This would be a lot of overhead and take up a lot of resources.
the first thing to know: the database in android is SQLite, So any other offline database it's just a layer for managing the SQLite database, and It only saves numeric and text data, but you can save any other type like image, audio, array...Ect by creating convertors to save it in the database.
E.g: You can save BitMap-Image type- by converting it to ByteArray-List of 0s and 1s-, then converting the ByteArray to String-Default text type-, then you can save it to the database, and when you want to select the value, just convert by the opposite (String -> ByteArray -> BitMap), So the trick here is to know how to convert between the types.
Now the answer:
the best offline-database is RoomDatabase, the fastest way to create and manage SQLite database, with Room you don't need to build an SQLite database from the scratch, it's going to build it for you, and has a great way to create converters.
but for you as a beginner, standard SQLite is more than enough, if you will see RoomDB more difficult.
I am looking for guidance in a proper way to use Firebase's Storage in order to synchronize some CSV files copies of which are stored in raw on the local device. I'm fairly new to Firebase storage.
Essentially, I wish to be able to push any changes made to the Firebase Bucket onto the local device. So anytime a CSV file is updated, a new one is added, or one is removed, I wish that to be synchronized with the copies stored on the device. Using the realtime database to store these CSV files in JSON is not an option for various reasons. It might also be worth mentioning that any file changes will be made by hand on the Firebase terminal.
I'm aware that Firebase allows us to list all the files contained at a reference point by calling .listAll() on a storage reference. However, I cannot find any documentation on this function or how to detect and update file changes.
Any help you can give me would be appreciated.
Cloud Storage for Firebase does not offer any APIs for automatically synchronizing objects in storage buckets between the client and server. It doesn't work at all like Realtime Database.
If you want to implement this, you will need to write a lot of code to implement that synchronization on your own. It won't be easy. You can take advantage of the sync provided by Realtime Database to reference which content might be new (if you store dates and paths to Storage), but ultimately, you will have to download and delete files manually as needed to make sure the client is up to date.
I am currently working with Fragments, one of my fragments is "User Profile" where the signed in user can edit and view their own profile. One of the requirements for this university project is that the user needs to be able to upload a profile picture and it should be allocated to their user profile and saved on the server (I am currently using Lampp on linux). I have the following questions:
When a user uploads an image using the Volley library (Android) does it first need to save the relative/absolute path of the image to the MySQL database, and then use this information to get the image in JSON format back onto the device, where it shall be cached?
I read online that the Volley library can cache images and videos on the device, which would help data consumption so the user doesn't need to download the image(s) every time they login again. But what if the user logs into the application from say an IOS device and uploads an image there and then they come back to the Android device and logs in there - the app needs to update their user profile.
My thinking was every time a new Image is uploaded to the server the time it was uploaded would be added to a Date/Time slot in the DB, then this time is stored is the SQlite DB and the MySQL DB, every time they open the application it makes a request to the MySQL DB requesting this time field and if no images have been added then the SQLite time and the one just pulled from the MySQL database will be the same so no need to download any images - I thought this would be a simple way of checking without using a lot of data? or is there a better option someone could suggest.
However, the problem with my above suggestion is say for example there are 5 images cached on the device, but a 6th one was added from another device, when we go back to the original device how do we only download the new image? and not all of the other 5 also which are already in the cache?
I think you need to store in db not path to image file, but URI that you pass into Volley. And then, when you want to show image pass saved URI in Volley and it will decide show cached image or upload from internet.
Good thoughts. I think in your case you can just show data cached in dp, and then additionally fetch data from server, and it was changed cache it and show new results. Also you can implements long polling, or sockets, or GCM to set up connection with server and fetch new updated data immediatelly (in real cases not immediatelly but faster then "go to app -> check from request if there was changes in server side").
And of course, please have a look to firebase tutorials to think about implementing on your server side this thing and provide more interesting and covenient connection with immediate update of your local cached data. additional link to video tutroial
I'm developing an Android application but I need some help.
I need to store about 2000 image in high resolution (1024x768 and about 2.5 MB each) and the application must work offline so i can't retrieve them from an online database or from anywhere else. These picture should be stored in the SQLite db inside the application because each one of them are related to a specific product.
I've tried to convert the picture to a Base64 string but the result is too big and the app crash. It works only if it's about 467x300 and 30 KB but it loose all its quality so this is not a good solution.
Hope you have helpful suggestions. Thank you.
The way this problem is typically solved is to not store the images in the database, but rather store a link to them in the database. If you want them to be private, store them in the private app storage location. Getting images from a database is tricky, and editing binary blobs like that can be tricky. It can cause issues in the database, which might cause things to be slower. Also, it's easier to load images from a file than from a database.
Also, you could use BLOB, which allows for storing binary data. SQLite supports that, so...
Here is what I did to handle my high resolution images:
give a unique image id to the image, stored in the database
save the image in the android storage
whenever I need a high res image, get its name from the database. use the name to look up the image from storage.
I'm happy to provide a code example, just let me know.
i am building a application for a takeaway resturant using SOAP as a webservice.
Problem:
When i try to open the application it loads every time. and if i have slow internet it will take some time which is not good for a professional application.
How can i cache the images in my mobile so it loads automatically
Possible Solution in my mind:
i think i should use the local database and sink it with internet
Use local cache system (but what if the application close).
Use arraylist to store information.
Can you guide me in that as i am stuck i do some reading but i don't feel any reliable solution on it.
You can use some libs but you can lose images if the app is closed.
Actually you can cache images with libs and save them to sdcard at the same time. You need to save Their id in database. Then take data from sdcard by id from database in case you haven't internet.