Whenever I upload an image to Firebase Storage, the file is only accessible through "download link".
What if I want anyone to access this file?
If I go to Google Platform Storage and enter the same bucket that Firebase uses, I can see that the "Public link" is unchecked.
How can I let this be automatically checked when photo has been uploaded?
Such actions can be done through Google Cloud Storage API, but there doesn't seem to be any option for this through Firebase.
Also, all images that are being uploaded via Firebase has a Content-Type of "application/octet-stream"
.
Since I am uploading an image, I would like this to have either "image/jpeg" or "image/png". Is there a way to change the metadata?
UPDATE: Reason why I am asking this is because if one create an app with an Instagram like feed of thousands of images. Requesting a download link for each image that is being fetched is unnecessary since the images in questions should already be open to public by default. Firebase file upload prevents this and each user therefor has to make one request per image (which can be tons of images per app launch). Firebase Flame subscription plan for instance has a limit of 100,000 downloads/uploads per month. This makes it unrealistic to create an image feed with thousands of users with thousands of image request each. Files should have the option to create a public link during upload, just as the Google Cloud Storage API itself.
There is no configuration to automatically check the public access checkbox of Google Cloud Storage for files that are uploaded through Firebase Storage.
That said, you could write a Google Cloud Function that triggers when a file is uploaded and that then changes the properties of the file, specifically, you'll want to change the object ACLs to be publicRead.
But since the download URL that Firebase generates for you is already publicly readable, I'm not sure what you gain by checking the box. Is there a specific use-case that you're looking for that isn't covered by simply sharing the download URL?
On the second part of your question, check out the File Metadata section of our docs, which shows you how to set the content type of a file:
// Create file metadata to update
FIRStorageMetadata *newMetadata = [[FIRStorageMetadata alloc] init];
newMetadata.contentType = @"image/jpeg";
// Update metadata properties
[myRef updateMetadata:newMetadata completion:^(FIRStorageMetadata *metadata, NSError *error){
if (error != nil) {
// Uh-oh, an error occurred!
} else {
// Updated metadata for 'images/forest.jpg' is returned
}
}];
Metadata can on added on upload as well, so there's no need for a second request.
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