How to store user photo in Firebase - android

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 :)

Related

Firebase Cloud Storage Android - Retrieving images with no cost

I am really confused about the process of retrieving and displaying images to your android app from firebase cloud storage. I looked around the web, but am unable to get a definitive answer to my questions.
With regards to my app, I simply want a place to store a bunch of images (around 2500) that I can display. I don't use authentication and I don't mind making these images public.
Do I have to request a download URL every time I want to retrieve an image from storage? I am worried because Firebase Storage allows you to download 1GB/day and only 50k/day download operations for free, which is not a lot of download operations for 2500 images.
Is there a way for me to access and display images without having to call reference.getDownloadUrl() ** every time I display an image?** Maybe some sort of workaround by making the images public and then storing the cloud storage URLs in a Room Database?
Any help is appreciated.
Do I have to request a download URL every time I want to retrieve an image from storage?
No, you can use the same URL repeatedly. Store that URL anywhere you like. But you will always pay the cost for egress every time the URL is accessed. There are no free downloads after the free allowance.
Is there a way for me to access and display images without having to call reference.getDownloadUrl() every time I display an image?
No, as I said above, you can reuse the same URL if you want. You can also configre the entire cloud storage bucket as public and simply build URLs to object as described in the links here. But again, downloads will be billed according to the normal Cloud Storage rates.
Please enable Firebase Storage for your bucket by visiting the Storage tab in the Firebase Console and ensure that you have sufficient permission to properly provision resources.",
"status": "ACCESS_BUCKET"

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.

Getting download url of multiple files inside Firebase Storage

I am creating an Android App where Firebase is the backed. In my app, I have some selected images that I have stored inside my Firebase storage by direct uploading (Without coding).
Now I have to view that images in my app through a recycle view. For that purpose, I have to get the download URL of all the images and put them into my Firebase real-time database programmatically so that I can access the URL to my app. Is there any methods available for that?
I have tried to iterate through storage, unfortunately there is no method for that.
There is currently no way to iterate a list of files in Firebase Storage using the Firebase SDKs. Instead, after you upload a file, you should also store its download URL in Firebase Realtime Database (or some other place) that you can query for the download URLs.
I was searching for a proper answer to this question for 2 days. What i found is, There is no proper API or Class in Firebase Storage for the same purpose. If you guys want to do the same effectively, get the files in your code programmatically and upload them to firebase storage through a loop. Through that you can get the download links after uploading of each files. Store it in the Real time Database of Firebase.
You can create a function that can can return a file. You can set up a /link url in the hosting to that function.

should I save user information in local database

I newbie to android programming and I have question which might sound silly.
I am writing app for a shopping store, which communicate with store's website
Every user must sign in to use the app.
In sign-in process, I save information like user name, address to send products and phone number in website's database.
I have 2 questions:
should I also save user information in local database(sqlite), so in case user would like to change stuff, I won't need to fetch it from web server?(or fetching it every time is better approach??)
The app, display list(picture+description) of products the user can buy(total 12 products).
the list can change every 2 weeks or month. should I save the images locally and have an AsyncTask to check if something changed and only then to download the delta, or should I download them every time.
Thanks in advance
Android provides support for user accounts so it's hard to say whether you can use that or whether you need to implement a custom solution without more details. Have a look here for some information on implementing authentication accounts
As for question 2, I would store the images locally as you say there are only 12. You could then have the server notify the mobile app (check out GCM) when there is an image update to pull from the server. You can also have a look at the Volley library which will assist you in retrieving and displaying images from a web server.
you can store any information in sqlite and use some cache(private/public) to store images for first time store images in cache and from second time onwards load images from that cache use volley library for server calls and image cache
http://developer.android.com/training/volley/index.html
for question two: no you don't need to save the pictures locally to keep your app using the minimum storage space.

What is the best way to handle feed in Android?

I have a situation, where I downloaded json string from server, like twitter or facebook or dropbox etc.
How should I store these data, so the data can be viewed during offline?
I implemented using SQLite, but worry if it is heavy for this job.
Thanks.
You have a few options.
Store in to the SQLite Database
Store the JSON/XML file locally and parse it when you need to display it.
I would suggest storing it in the database too.

Categories

Resources