You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constadmin=require('firebase-admin');constserviceAccount=require("./serviceAccount.json");admin.initializeApp({credential: admin.credential.cert(serviceAccount),storageBucket: `${serviceAccount.project_id}.appspot.com`,});asyncfunctionuploadTest(){// Get storage bucket refconstbucket=admin.storage().bucket();constimage="./my-image.jpg";// Upload itconst[file]=awaitbucket.upload(image);console.log(`uploaded ${image}`);// Make publictry{awaitfile.makePublic();}catch(err){console.error("error making file public",err);}// Get public URLconsole.log(file.publicUrl());}uploadTest()
The public URL of the file is printed to the terminal.
[REQUIRED] Actual behavior
The file is present in the storage emulator UI, and is listed as having the correct size, but the file.makePublic() call is failing - see entire output below:
In the meantime you can work around it by using read: true in your storage rules and using the Firebase Storage URLs instead of Cloud's.
If your Storage security rules support unauthenticated reads you can just generate a url likehttps://firebasestorage.googleapis.com/v0/b/${bucketName}/o/${encodeUriComponent(pathToFile)}?alt=media and it'll be public. For example, here's a file in my public bucket https://firebasestorage.googleapis.com/v0/b/abe-today.appspot.com/o/public%2F1_3_Bill.png?alt=media, it's a little different, but its a bit more Firebasey :)
[REQUIRED] Environment info
firebase-tools:
9.11.0
Platform: Manjaro Linux
[REQUIRED] Test case
upload-test.js:
[REQUIRED] Steps to reproduce
Terminal 1:
Terminal 2:
[REQUIRED] Expected behavior
The public URL of the file is printed to the terminal.
[REQUIRED] Actual behavior
The file is present in the storage emulator UI, and is listed as having the correct size, but the
file.makePublic()
call is failing - see entire output below:The text was updated successfully, but these errors were encountered: