My Firebase Storage getSignedUrl()
download links work for a few days, then stop working. The error message is
SignatureDoesNotMatch
The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.
Last summer there was a long discussion of this on GitHub but I don't see that a solution was reached.
I'm thinking of using getDownloadURL()
from the front end instead of using getSignedUrl()
from the back end. Is getDownloadURL()
less secure then getSignedUrl()
?
Here's my code, which is mostly copied from the documentation:
let audioType = 'mp3';
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket('my-app.appspot.com');
var file = bucket.file('Audio/' + longLanguage + '/' + pronunciation + '/' + wordFileType);
// Firebase Storage file options
var options = {
metadata: {
contentType: 'audio/' + audioType,
metadata: {
audioType: audioType,
longAccent: 'United_States',
shortAccent: 'US',
longLanguage: 'English',
shortLanguage: 'en',
source: 'Oxford Dictionaries',
word: word
}
}
};
const config = {
action: 'read',
expires: '03-17-2025',
content_type: 'audio/mp3'
};
function oedPromise() {
return new Promise(function(resolve, reject) {
http.get(oedAudioURL, function(response) {
response.pipe(file.createWriteStream(options))
.on('error', function(error) {
console.error(error);
reject(error);
})
.on('finish', function() {
file.getSignedUrl(config, function(err, url) {
if (err) {
console.error(err);
return;
} else {
resolve(url)
}
});
});
});
});
}
You specify triggers as part of function deployment. You cannot bind the same function to more than one trigger at a time, but you can have the same event cause multiple functions to execute by deploying multiple functions with the same trigger settings. Note: Trigger binding does not happen instantaneously.
gsutil is a Python application that lets you access Cloud Storage from the command line. You can use gsutil to do a wide range of bucket and object management tasks, including: Creating and deleting buckets. Uploading, downloading, and deleting objects.
Go to the Google Cloud Console and the Cloud Functions dashboard. Select Create Function. Fill out the name of the function to use in the URL for the HTTP Trigger. Also choose the Trigger to use.
The maximum duration of a Google Cloud Storage Signed URL is 7 days. But it can also be shorter. Never longer. I guess the Firebase Storage has the same limit.
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