I am trying to upload a file to Firebase Cloud Storage using a signed URL, as described in the docs: https://cloud.google.com/storage/docs/access-control/signed-urls#signing-resumable
I'm using the node.js Admin SDK.
I'm getting a signed URL which looks valid, but when sending the POST request for getting the Session URI, I'm getting the following error:
<?xml version='1.0' encoding='UTF-8'?><Error><Code>AccessDenied</Code><Message>Access denied.</Message><Details>Anonymous caller does not have storage.objects.create access to projname.appspot.com/filename.ext.</Details></Error>
Here's the code I'm using to make the request:
const admin = require('firebase-admin');
const axios = require('axios').default;
const queryString = require('query-string');
const serverKey = require(<server key path>)
admin.initializeApp({
credential: admin.credential.cert(serverKey),
storageBucket: "projname.appspot.com",
});
async function run() {
const bucket = admin.storage().bucket()
const file = bucket.file(`filename.ext`)
var expires = new Date()
expires.setTime(expires.getTime() + (12 * 60 * 60 * 1000))
const signedUrlArr = await file.getSignedUrl({
action: 'resumable',
expires: expires,
})
const signedUrl = signedUrlArr[0]
const qsArr = signedUrl.split('?')
const params = queryString.parse(qsArr[1]);
try {
const options = {
headers: { "x-goog-resumable": "start" }
};
const response = await axios.post(
qsArr[0],
{ params },
options,
)
console.log(response)
} catch (e) {
console.error(e.response.data)
}
}
run();
The service account used to run the cloud function has the Editor, Service Account Token Creator and Storage Object Creator permissions (had to add the last two so I could generate a signed URL.
I don't think this is readlly a lack of permissions because the error message says the request is made from an anonymous user, which isn't the case.