从使用Cloud Functions for Fire上传的文件获取下载网址 [英] Get Download URL from file uploaded with Cloud Functions for Firebase
问题描述
我有这个:
...
返回桶
.upload(fromFilePath,{destination:toFilePath})
.then((err,file)=> {
//获取文件
}的下载网址);
目标文件有很多参数。即使是一个名为 mediaLink
的。然而,如果我尝试访问这个链接,我得到这个错误:
匿名用户没有storage.objects.get访问to object ...
有人可以告诉我如何获得公开下载Url吗?
谢谢
您需要使用 getSignedURL 通过 @ google-cloud / storage NPM模块。
示例:
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]包含文件的公共URL
});
您需要初始化 @ google-cloud / storage
与您的服务帐户凭据作为应用程序默认值凭证是不够的。
After uploading a file in Firebase Storage with Functions for Firebase, I'd like to get the download url of the file.
I have this :
...
return bucket
.upload(fromFilePath, {destination: toFilePath})
.then((err, file) => {
// Get the download url of file
});
The object file has a lot of parameters. Even one named mediaLink
. However, if I try to access this link, I get this error :
Anonymous users does not have storage.objects.get access to object ...
Can somebody tell me how to get the public download Url?
Thank you
You'll need to generate a signed URL using getSignedURL via the @google-cloud/storage NPM module.
Example:
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
});
You'll need to initialize @google-cloud/storage
with your service account credentials as the application default credentials will not be sufficient.
这篇关于从使用Cloud Functions for Fire上传的文件获取下载网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!