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

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/

Related

hi, i am trying to retrieve data (an image particularly) from Firebase Database to android but not success

I want to retrieve the image of the connected user like on play stores app in drawer menu but not a success and I don't know how to proceed. I have succeeded to show the user's name and email but not the image.
Imagining you have url of the images stored in firebase server you can use GLIDE library (library link) to download and display the images from any server not only firebase
If you don't have the image stored in database then you should first store it and then retrieve it from url. you can learn how to do it from here

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.

Android Firebase Storage Image Retrieval associated with Database Object

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?

How to store user photo in Firebase

I'm wondering what is proper way to store users avatar/photo/Image from FirebaseUser.getPhotoUrl().
My first idea was simple, store URL to this images as normal String, and It would be great if not the fact that facebook URLs expires.
So my second idea was to fetch these images and store as Base64 String, but then I got to my third idea which is Firebase Storage, but I'm wondering if it is too slow to store so small and dynamic content as users avatars.
Don't store it in Firebase Storage or the Realtime Database, just download it directly from the URL and cache it locally. No reason to store the same thing twice :)

Categories

Resources