您需要通过@ google-cloud / storage
NPM模块使用getSignedURL生成签名URL
。
例:
const gcs = require('@google-cloud/storage')({keyFilename: 'service-account.json'});// ...const bucket = gcs.bucket(bucket);const file = bucket.file(fileName);return file.getSignedUrl({ action: 'read', expires: '03-09-2491'}).then(signedUrls => { // signedUrls[0] contains the file's public URL});您需要
@google-cloud/storage使用服务帐户凭据进行初始化,因为应用程序默认凭据不足。
更新 :现在可以通过Firebase Admin SDK访问Cloud Storage
SDK,该软件充当 @ google-
cloud / storage
的包装。唯一的方法是:
- 通常通过第二个非默认实例,使用特殊服务帐户初始化SDK。
- 或者,在没有服务帐户的情况下,通过向默认的App Engine服务帐户授予“ signBlob”权限。



