Upload image in firebase Storage using a link - android

I want to upload images in firebase storage. I know how to upload images in firebase using Uri. But is there a way in which I can upload images to firebase using a link?
I am using an API in my project and I can only hit it 1000 per month so I am trying to save images in firebase as soon as it is fetched from API.
the API gives a link to the image which I use to show images in imageview with Picasso.
suppose my link is http://xxx.xx.xxx.......png? I have converted it into Uri
using Uri.parse(link). Firebase gives me an exception when I try to do so.
The exception
StorageException: No content provider: http://xx.xx.com/xx/xx/xxx/xx/xx.png?
java.io.FileNotFoundException: No content provider: http://xx.xx.com/xx/xx/xx/xx/xx.png?

The Firebase Storage SDK will not work with remote files like that. You can't pass it an HTTP URL and expect that it will download that remote file, then upload it to storage. You have to download the remote file first, then upload it.
If it's not clear, the Uri that you pass it must refer to a local file only.

Related

Android Firebase Storage

I am developing an Android app to share doc(generally pdf) between student and teachers(two different app one as a server and another as a client).Uploading a file to the firebase storage is done. The problem is that I want a list of uploaded file with download thumbnail/button in the student app. How to do it?
Please help me out.
I don't think you can do it as there is no API till now. All you can do is Store the link generated for each file in the Realtime database and then use this list of URL.
Or use cloud functions to manipulate your uploads and then store generated URL in some file and retrieve this file for list of files.
For more please refer this post.
https://stackoverflow.com/a/37337436/4517450
https://firebase.google.com/docs/database/

In Flutter how do I show offline images from Firebase using CachedNetworkImage?

I'm trying to make my Flutter app work offline with Firebase. I store a reference to my images on Firestore and the image files on Storage. I got the Firestore part working, and I'm using a CachedNetworkImageProvider to display my images, which caches for offline use. But when I'm offline, even though the image is cached, I can't get the URL for the image, so I can't pass it to CachedNetworkImageProvider, which uses the URL as the key.
So while offline I know the image path, and I have the file stored on device, I just need a way to get the URL.
Do I need to manually store the download URLs from Storage on the device so that I can use them offline? Or is there a better way?
Code to get the URL:
// this doesn't work offline
category.url = await storage
.ref()
.child("category_images/drawable-${DeviceInfo.dpiString}")
.child(document.data["media"]["src"])
.getDownloadURL();
Code to display the image:
image: new CachedNetworkImageProvider(_category.url),
You need to save the URL too. A good place could be in that image reference you have in firestore.
The other option is to use the local file since you say you know the path, though I think referring through the URL is cleaner.

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.

Externally link to files stored on Firebase Storage?

Is there any way possible to get a direct URL to download the media file which I have uploaded onto the Firebase storage using my Android app?.
Scenario 1 :- I am basically looking for a http or a https URL which I can paste it in the browser and the image can be downloaded.
Scenario 2:- I can get a public url so that I can write a download manager in my web app which can download the images from these urls.
Also, If possible I want it to be completely independent of any reference of firebase database.
Thanks in advance.
When you upload the file, a URL for the stored file is available in the returned UploadTask.TaskSnapshot. You can also obtain the URL from a StorageReference using getDownLoadUrl().
An example can be found in the Firebase Quickstart project.
You can use Fibrebase SDK on your server-side to download any stored file to serve it when a client requests it by name for example.

Categories

Resources