简体   繁体   English

从Google云端存储中获取更短的文件网址(使用Firebase云功能)

[英]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.

相关问题 使用下载 url 和 Cloud Functions 从 Firebase 存储中删除文件 - Delete a file from firebase storage using download url with Cloud Functions 从使用 Cloud Functions 上传的文件中获取下载 URL for Firebase - Get Download URL from file uploaded with Cloud Functions for Firebase 从 Google Cloud Storage 获取永久 URL? - Get a permanent URL from Google Cloud Storage? 从Firebase云功能获取云存储文件 - get cloud storage file from firebase cloud function Firebase Cloud函数使用url从存储中删除孤立图像 - Firebase Cloud functions remove orphan image from storage using url 如何从服务器上的 Firebase 函数访问 Google Cloud Storage - How to access Google Cloud Storage from Firebase functions on the server 如何将firebase云功能中的文件从url上传到firebase存储? - How to upload file in firebase cloud function into firebase storage from url? 使用http cloud云功能从Firebase云存储下载文件时,没有此类文件或目录 - no such file or directory when downloading a file from firebase cloud storage using http cloud cloud functions 将存储与Google Cloud Functions for Firebase结合使用 - Use Storage with Google Cloud Functions for Firebase 使用 firebase 函数重定向到 URL - 谷歌云函数 - Redirecting to URL with firebase functions - google cloud functions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM