Firebase Cloud Storage download url vs path - firebase

I'm new to firebase storage and wants to know what is the best practice.
I want to upload image to firebase cloud storage and was returned a download url which I then stored to firestore. Is the download url permanent? Other users will read from the firestore to get the url to download the image.
But when I want to delete the image from CloudStorage, I only have the download url but not the file path. So do I delete it ?
If I store the file path instead, how to get the download url ?

Is the download url permanent?
The download URL will work until you revoke it.
I only have the download url but not the file path. So do I delete it?
You can get a StorageReference from a download URL by calling FirebaseStorage.getReferenceFromUrl() (or the equivalent for your platform).
If I store the file path instead, how to get the download url?
You can create a StorageReference for the path with FirebaseStorage.getReference(), and then call StorageReference.getDownloadUrl().

I know it's an old post but this is what I use in Flutter:
final Reference storageReferenceFromUrl = FirebaseStorage.instance.refFromURL(downloadPhotoPath!);
storageReferenceFromUrl.delete();
Hopefully, this helps.

Related

Firebase: Batch upload nested folders and files to Google Cloud Bucket

I want to upload nested folders and files to a Google Cloud Bucket.
So far I used this command line to do so:
gsutil -m cp -R [dir] gs://[bucket]
it works, but when I go to Firebase console, I cannot generate an access token for the uploaded files.
If I upload the same file manually the access token is generated automatically.
I wonder if there's a way to make gsutil to upload in a manner that files will have access token.
Appreciate your hints and conversations
Download URLs are normally only generated by the Firebase SDK for Cloud Storage.
Luckily though somebody figured out that if you set the right metadata for a file, that gives it a download URL too. Since metadata can be set through gsutil, that means it should be possible to also generate download URLs like that.
See:
Get Download URL from file uploaded with Cloud Functions for Firebase, for the metadata to set
The gsutil documentation on setting metadata

Download URL not present in Firebase Console

There is no url present in the file location of firebase storage. Instead it gives a storage path. Please help.enter image description here
Just click the image and there is your URL:
To get the URL through Flutter, you can follow this answer:
https://stackoverflow.com/a/54086124/11231634
Download URLs are not/no longer automatically generated when you add a file to Cloud Storage through the Firebase SDK. Instead you will have to call getDownloadURL() to generate such a download URL. This URL will then also show up in the Firebase console.
Unfortunately, in my case, some files cannot be downloaded as Vitor suggests. I don't know why, but there's just a plain text instead of link.
Solution
Just download it via Cloud Storage at Google Console. This works every time.

Manually uploading files to Firebase storage and adding it to Firestore

I have an app that all it does is to present PDF documents that is stored in Firebase.
I've created a collection in Firestore with all the relevant information for the documents (title, description etc.) and all is left to do is to provide a download URL to the PDF itself.
I've uploaded the PDF manually to Firebase Storage, but I couldn't find a way to manually copy the file URL in order to paste it in the Firestore.
How can I add the URL for the files Manually? (My client doesn't write code and he needs to update the files constantly).
Thank you!
Simply click the link shown in the picture below, then copy the URL it directs you to.

Firebase Storage gs url to http

I downloaded a Unity project that use images stored in Firebase server using the following link:
https://zplayer360-86b30.firebaseapp.com
Now I want to reproduce this with my own file. I created a Firebase project using Firebase Console, uploaded manually the images, but now I click "copy folder url" button and it provide me only this link:
gs://insidehome-29c9e.appspot.com/
I need a free HTTP public link.
How can I obtain this?
When you upload a file to Firebase Storage, it automatically gets:
a Google Storage URL (starting with gs://), which you can use to access the file through the Firebase Storage SDK and the Google Storage API.
a download URL (starting with https://), which is a publicly-readable-but-non-guessable URL that you can use to download the URL with regular HTTP clients
What you're looking for is the second URL, which you can find in the Firebase Storage console when you select a file:
At the bottom right you can see the download URLs for the file. One of these is auto-created when you upload the file, but you can create more of them or revoke existing ones.
I am not entirely sure what you mean by "free" URL. The link is publicly readable, but downloads will count against your Firebase Storage download quota of course.
If there are no rules on Firebase storage. You are not protected.
Then it's publicly-readable-and-guessable, One can convert gs:// URL to https:// to download any file without Google SDK's.
https://firebasestorage.googleapis.com/v0/b/[projectID].appspot.com/o/[folderName]%2F[fileName]
Google Storage URL
gs://invitepeople-5d38c.appspot.com/profilePhotos/profile_1.jpg
Https downloadable URL
https://firebasestorage.googleapis.com/v0/b/invitepeople-5d38c.appspot.com/o/profilePhotos%2Fprofile_1.jpg?alt=media
Don't guess profile_2.jpg :)

Get the uploaded document url through alfresco

I am very new to alfresco(using version 3.4). I have written a document library action to validate the uploaded file. Now I want path of uploaded file so that I can pass it to my service to validate. Can any one tell me how could I get the downloadable path of a document ??
THanks....
I don't know how you've build your action. But on the client side Javascript you could access file.path.
On the repository side webscript, the normal action imports action.lib.js.
In which the path variable is available.
If you take a look at e.g. Backup Action in the googlecode project share-extra's then you'll probably will know what I mean.
The URL download path?
If you know the nodeRef of the document, you can construct the path yourself.
Here's an example:
http://localhost/share/proxy/alfresco/api/node/content/versionStore/version2Store/169c2842-6bc8-4ace-9b9f-1a46aebb100b/MyFile.pdf?a=true
Everything up to and including the "version2Store" is fixed, and then you have the nodeRef/file part. That's the download link for a document (assuming the user is logged in and can have access to the document or the document is accessible for guests.

Resources