我有一个小任务,其中需要一个文档或文件的 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/