I am building a cross platform mobile application that uses Firebase for its data storage and user authentication. I am also using an SDK which requires a direct URL to some mp4 files. So far we have hosted these video files on a separate server, but due to the simplicity/scalability of Firebase, I'd like to store them on it rather than separately. I need to be able to have a direct URL to the file, however.
When I go to access a test file from my browser using the file's Firebase storage location, for example:
APPNAME.appspot.com/RESOURCENAME.mp4
I get a 404 error.
I have set my rules to the following:
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow write: if request.auth != null;
allow read: if true;
}
}
}
Is there a way to access a Firebase Storage resource directly from a URL?
EDIT: I should add that I require a url that is not randomly generated, but rather based on the file's logical location in storage, since the resource file is accessed dynamically based on the file's UUID in the application. There are also too many files to store/look up an unguessable link.
While this isn't the answer to your question, you should really be using Firebase Hosting for this purpose. Firebase Storage is geared more towards User uploads and sharing than static content.
Uploading to hosting is super simple using the Firebase CLI. https://www.youtube.com/watch?v=meofoNuK3vo You just put the files you want to host in the 'public' folder and run firebase deploy.
The default access to the files in Cloud Storage is governed by your security rules. That is intentional.
But whenever you upload a file through the Firebase SDK, it also generates a so-called download URL for that file. The download URL is an unguessable URL that provides read-only access to the file. It is made for sharing with other users of the app in the way you describe here.
To generate a download URL, follow the instructions in the docs here: https://firebase.google.com/docs/storage/ios/download-files#generate_a_download_url (similar sections exist in the docs for other platforms).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With