我具有firebase功能,可将文件上传到firebase存储,上传后,我必须返回url(作为Reset响应),以便用户可以查看文件
const bucket = admin.storage().bucket();
const [file, meta] = await bucket.upload(tempLocalFile, {
destination: uploadPath,
resumable: false,
public: true,
});
我有两个选择
1- const signedUrl = await file.getSignedUrl({ action: 'read', expires: '03-09-2491' });
2- meta.mediaLink
SignedUrl类似于https://storage.googleapis.com/web-scanner-dev.appspot.com/pwc%2Fwww.x.com%2F2019-11-17%2Fdesktop%2Fscreenshot-2019-11-17-1125.png?GoogleAccessId=firebase-gcloud%40scanner-dev.iam.gserviceaccount.com&Expires=16447035600&Signature=w49DJpGU9%2BnT7nlpCiJRgfAc98x4i2I%2FiP5UjQipZQGweXmTCl9n%2FnGWmPivkYHJNvkC7Ilgxfxc558%2F%2BuWWJ2pflsDY9HJ%2Bnm6TbwCrsmoVH56nuGZHJ7ggp9c3jSiGmQj3lOvxXfwMHXcWBtvcBaVj%2BH2H8uhxOtJoJOXj%2BOq3EC7XH8hamLY8dUbUkTRtaWPB9mlLUZ78soZ1mwI%2FY8DqLFwb75iob4zwwnDZe16yNnr4nApMDS7BYPxh4cAPSiokq30hPR8RUSNTn2GxpRom5ZiiI8dV4w%2BxYZ0DvdJxn%2FW83kqnjx6RSdZ%2B9S3P9yuND3qieAQ%3D%3D
和mediaLink就像https://storage.googleapis.com/download/storage/v1/b/web-scanner-dev.appspot.com/o/pwc%2Fwww.x.com%2F2019-11-17%2Fdesktop%2Fscreenshot-2019-11-17-1125.png?generation=1574007908157173&alt=media
每种技术的优缺点是什么?
答案 0 :(得分:1)
mediaLink
本身不会传递任何访问权限-因此,对象本身必须为publicly readable才能使最终用户使用该链接(否则您将需要在执行链接时被身份验证为对该存储桶具有读取访问权限的帐户。
另一方面,由getSignedUrl
返回的URL将具有allows access的签名,只要该URL尚未过期。因此,仅链接就足够(如果是临时的)访问Blob的权限。此外,所生成的URL保留创建该URL的用户的权限-如果该用户在链接失效之前就失去了对该Blob的访问权限,则该链接将不再起作用。