Android Firebase Storage Image Retrieval associated with Database Object - android

I am currently storing an Object in a Firebase Database containing name, description and base64 of a photo. I know this is not a good practice but it works for now. I have some knowledge how to upload to a firebase storage and how to retrieve an image. Let's say I want to upload an object do a database containing name and description and also a photo but this time to the storage. And let's say there is 100 of those objects with 100 images. What should I do that each object is associated with the correct image?

Related

save images uploaded from user gallery so other users can see it

I am using firebase database for saving my data. The user can upload his own personal photo as profile picture from gallery. I want other users to be able to see the photo as well. I am currently saving the image path in database but that only works fine if both users share the same device. So how to save image in database so it is accessible by all users using different devices
You must upload the image to Firebase Storage and store the download URL into the realtime database
OR ideally, convert the image to base64 string and save that to the user's UID. Just ensure you are compressing and resizing the image beforehand and validate its length (length is relative to the image size) through Security Rules or through Cloud Functions.
The resulting structure would be as follows:
users-
UserID_A -
name: "Steven"
avatar: "(random Base64 string)"
UserID_B -
name: "Jane"
avatar: "(random Base64 string)"
Reference: https://www.programmersought.com/article/67005590348/

Get image from Firebase Storage, from different Fragment from where It was uploaded

I have uploaded images to Firebase Storage I a Fragment called, PostAJobFragment. In this fragment the user enters details, such as the job name, description and they must upload an image.
The data such as the name and description are saved in the Firebase Database and the Image is saved In the Firebase Storage area.
All of the Jobs that are uploaded the the Database Area are saved under a unique key. The same unique key is used to store the image relating to that Job in the storage area.
So, lets say the Job in the database has a key "-L8rPGlikrxBnkP5PzLC", the same key is used in the storage are to store the Jobs Image.
Is their an efficent and easy way to get the image out of the Firebase Storage area to display to the user again on different Fragments?
So far I have saved the URL address for the image under the Job in the database and used Picasso to display the image. I feel their must be a better way than this?
Example of Database Structure

retrieve images from firebase storage to recyclerview without database

Hi guys I am making a wallpaper android app.I have stored all my images in firebase storage. Now I have a recyclerview and want to retrieve each of the images into that recyclerView by getting list url of the folders.Is there any way to do that without using the database.I have pasted the json file into my app.
In order to download a image/images from Firebase Storage, you first need to have the corresponding url/urls. To download an image, it requires four steps:
Upload the image to Firebase Storage.
Save the corresponding URL to Cloud Firestore/Firebase Database database while uploading.
Attach a listener on the folder you have saved the image.
Display the image.
So there is no way in which you can download an image without knowing the URL. You cannot get the image list URL directly from Firebase Storage.
First at all you need to have corresponding URLs of your image data stored in Firebase, as mention Alex Mamo. You can build list of this urls during upload or copy them from Firebase Console. Storage API doesn't provide any way how to retreive list of stored files.
Also, you can find Download URL in Image detail/properties. Then you can insert urls into JSON file (or another file, service, firebase storage, whatever) and load them in app.
But be careful, this is not a good idea because Firebase Storage (especially spark plan has limits) allow you download 1GB/day and only 50k/day (download/upload) operations. That will be wasted pretty soon if you don't optimise your data and number of reading operations.
Tip: When you select pay as you go most expensive is GB Downloaded, so you absolutely should store at least 1 thumbnail which will be shown in your recycler view.

Image storing in SQL DB from Android

I would like to create an application which accepts image in android convert it to base64string. The resulting base64 string will be sent to the rest API where it is converted to byte array and store in SQL DB. Is this the best possible way to store image in SQL DB or there any other possibilities?
Better practice is to store the string of the location on the filesystem where the service that executes your database call is hosted. When you retrieve the 'image' you retrieve the location and use that to pull back the image from the file system rather than storing the entire binary on the database.
This is My way , I will just say in simple way .first i create global path like "yourpath/"
then I Get image from server and Store it in device storage in the global path
then I Store only image name like imagename.jpg to the sqlite
at last I use image name stored in sqlite and concatenate with global path to display images whenever I want

to retrieve already stored image from database in android

I am new to android. I would like to know how to retrieve stored images from a database. No add or delete functionality. I want to retrieve already stored images from a database. Please help me achieve this.
This answers assumes that you are retrieving images from a database in another app (because you'd already now how to retrieve images from a database that you created).
If the database is within another application, you must use a content provider. This link will redirect you to the official documentation. It covers all you will need to know about content providers.
In the most basic terms ever, to use a content provider you must first ask permission. Then you query the application that stores the database rather than the database itself (note: the application you query in turn queries the database). Therefore, you must have documentation that will provide predefined methods that must be used.
Not sure what really you want.
But if you finding a simple way to store image to database, you can try base64 image, it is like a string so simple store and read it in/from database.
To display base64 image on html, use can you
<img src="data:image/gif;base64,base64_data_here"/>
Reference to more information:
To convert your image to base64
How to convert a image into Base64 string?
To convert base64 to image:
How to convert a Base64 string into a BitMap image to show it in a ImageView?

Categories

Resources