node.js - 如何使用node.js在firebase中存储文件

标签 node.js firebase google-cloud-storage firebase-storage

我有一个小任务,其中需要一个文档或文件的 URL,例如 google 云端硬盘链接或 Dropbox 链接。

我必须使用此链接使用nodejs将该文件或文档存储在firebase中。我应该如何开始?

抬起头可能会有所帮助。我应该用什么?请帮助我被困在这里。

最佳答案

使用管理 SDK 的文档主要包含在 GCP documentation 中。 .

下面的代码片段展示了如何将图像直接上传到 Cloud Storage(如果您有图像的 URL)。任何公共(public)链接都有效,无论是从 Dropbox 还是互联网上的其他地方共享。

编辑于 2020-06-01 SDK v2.0(2018 年 9 月 4 日)中删除了直接从 URL 上传的选项:https://github.com/googleapis/nodejs-storage/releases/tag/v2.0.0

const fileUrl = 'https://www.dropbox.com/some/file/download/link.jpg';
const opts = {
  destination: 'path/to/file.jpg',
  metadata: {
    contentType: 'image/jpeg'
  }
};

firebase.storage().bucket().upload(fileUrl, opts);

此示例使用应用程序中的默认存储桶,opts 对象为 API 调用提供文件上传选项。

  • destination 是您的文件在 Google Cloud Storage 中上传到的路径
  • 元数据 应描述您正在上传的文件 ( see more examples here )
    • contentType 是文件 MIME type您正在上传的内容

关于node.js - 如何使用node.js在firebase中存储文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53969468/

相关文章:

javascript - 让所有网站路径在 express 中加载相同的静态网站

ios - 使用 FCM Java API 发送 APNS mutable_content

ios - Swift3 Firebase 检索数据

java - Firebase 无法保存任何数据

kubernetes - 没有 Google 云存储的 Kubeflow

c++ - 强制 node-gyp 使用 C++11

node.js - 在 Node.js 中检查存储桶是否准备就绪的最佳方法

python-3.x - 如何通过谷歌云功能触发云存储中的特定扩展文件

cors - 使用在 gsutil 中配置了 cors 的 PUT 方法上传到 Google Cloud Storage 时没有访问控制允许来源

node.js - Amazon SES 电子邮件不再发送