Google Cloud Function中的getSignedURL()会生成有效数天的链接,然后返回“SignatureDoesNotMatch”

问题描述 投票:0回答:2

我的Firebase存储getSignedUrl()下载链接工作了几天,然后停止工作。错误消息是

SignatureDoesNotMatch
The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.

去年夏天在GitHub上有一个很长的discussion,但我没有看到解决方案达成。

我想从前端使用getDownloadURL()而不是从后端使用getSignedUrl()getDownloadURL()不如getSignedUrl()安全吗?

这是我的代码,主要是从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)
            }
          });
        });
      });
    });
  }
node.js firebase google-cloud-storage firebase-storage
2个回答
1
投票

Google云端存储签名URL的最长持续时间为7天。但它也可以更短。永远不会。我猜Firebase存储有相同的限制。


0
投票

我在这个问题上写了一个很长的答案:[Get Download URL from file uploaded with Cloud Functions for Firebase。此问题可以标记为重复。



  [1]: https://stackoverflow.com/questions/42956250/get-download-url-from-file-uploaded-with-cloud-functions-for-firebase
© www.soinside.com 2019 - 2024. All rights reserved.