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)
}
});
});
});
});
}