[英]Get shorter file URL from Google Cloud Storage (with Firebase Cloud Functions)
I have the following Firebase Cloud Function to get the URL of the file stored in Google Cloud Storage. 我有以下Firebase云功能,以获取存储在Google云端存储中的文件的网址。
const gcs = require('@google-cloud/storage')({keyFilename: 'service-account.json'});
exports.generateFileLink = functions.storage.object().onChange(event => {
const object = event.data;
const filePath = object.name;
const bucket = gcs.bucket(object.bucket);
const file = bucket.file(filePath);
const action = 'read';
const expires = '03-09-2491';
return file.getSignedUrl({action, expires}).then(signedUrls => {
console.log(signedUrls[0])
});
})
This returns the correct URL, but it is over 600 characters long. 这将返回正确的URL,但长度超过600个字符。 The URL for the same file as seen on the Firebase web console is less than 200 characters long. Firebase Web控制台上显示的同一文件的URL长度少于200个字符。 Is there any way I can retrieve the URL using firebase-admin or firebase-functions modules to get the shorter URL? 有没有什么办法可以使用firebase-admin或firebase-functions模块检索URL以获得更短的URL?
Short answer is that we're working on a firebase-admin
Storage client, but it's still a little ways away. 简短的回答是我们正在开发一个firebase-admin
存储客户端,但它还有一段距离。 For now, signed URLs are the way to go if you need to create a download URL in a function. 目前,如果您需要在函数中创建下载URL,则可以使用签名URL。
Why do you need to generate signed URLs in the function vs using the download URLs provided by Firebase? 为什么需要使用Firebase提供的下载URL在函数中生成签名的URL? Is it that you can't retrieve the URL via a client in the function and you need to move it somewhere else? 是不是你无法通过函数中的客户端检索URL,你需要将它移动到其他地方吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.