在NodeJS服务器端保护Firebase存储的外部链接 [英] Secure external links for Firebase Storage on NodeJS server-side

查看:168
本文介绍了在NodeJS服务器端保护Firebase存储的外部链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在生成外部链接到我的Firebase存储分区中存储的文件时遇到问题。



我现在正在使用Google云端存储,并使用这个库(基于答案)用于为常规存储桶生成外部链接,但是在Firebase分配的桶上使用该链接并不会我不能生成任何安全的HTTPS链接,并继续获取证书验证错误 NET :: ERR_CERT_COMMON_NAME_INVALID 指出我的连接不是私人的。如果我从HTTPS中删除S,则链接将起作用。
$ b 注意:使用相同的凭证和私钥生成链接在我的项目中的其他桶,工作得很好。只有Firebase存储桶拒绝接受我的签名... 解决方案

我推荐使用官方的 GCloud客户端,然后您可以使用 getSignedUrl() 得到(b

$ b

  bucket.file(filename).getSignedUrl({
action: 'read',
expires:'03 -17-2025'
},function(err,url){
if(err){
console.error(err);
return;
}

//现在可以从这个URL读取文件
request(url,function(err,resp){
// resp.statusCode = 200
});
});

每个,似乎可以与Firebase和GCS存储区配合使用。


I'm having issues generating external links to files stored in my Firebase Storage bucket.

I'm using Google Cloud Storage for a while now and used this library (which is based on this answer) for generating external links for regular Storage buckets, but using it on the Firebase-assigned bucket doesn't seem to work.

I can't generate any secure HTTPS links and keep getting certificate validation error NET::ERR_CERT_COMMON_NAME_INVALID stating that my connection is not private. If I remove the 'S' from the HTTPS, the link works.

NOTE: Using the same credentials and private key to generate links for other buckets in my project, works just fine. It's only the Firebase bucket that is refusing to accept my signing...

解决方案

I recommend using the official GCloud client, and then you can use getSignedUrl() to get a download URL to the file, like so:

bucket.file(filename).getSignedUrl({
  action: 'read',
  expires: '03-17-2025'
}, function(err, url) {
  if (err) {
    console.error(err);
    return;
  }

  // The file is now available to read from this URL.
  request(url, function(err, resp) {
    // resp.statusCode = 200
  });
});

Per Generate Download URL After Successful Upload this seems to work with Firebase and GCS buckets.

这篇关于在NodeJS服务器端保护Firebase存储的外部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆