javascript - 使用 https 流将文件上传到 Firebase Ddmin SDK (GCS)
问题描述
当尝试将流上传到 Google 存储桶时,我Error: Not Found
在使用 get 方法时得到,并且Error: socket hang up
在使用 request 方法时会延迟几秒钟。
firebase 的一切似乎都初始化得很好,当我记录流时,我看到数据通过了,但是使用远程 URL 将文件写入 GCS 的最佳方法是什么?
const storage = firebase.storage()
const bucket = storage.bucket("bucket/path")
const file = bucket.file("filename.pdf")
const url =
"https://url/to/file/filename.pdf"
https.get(url, async (res) => {
console.log(res)
res.pipe(file.createWriteStream())
})
解决方案
问题的原因是将文件夹路径传递到存储桶名称而不是文件名。
Bucket 名称在存储控制台中可用,不要传入文件夹路径。
存储桶名称示例:(
gs://bucket.appspot.com
将 gs:// 作为值传递时删除)
const bucket = storage.bucket("bucketname")
const file = bucket.file("bucket/path/filename.pdf")
推荐阅读
- java - 防止对多对多实体进行循环 JSON 转换
- python - 在 1 个图中添加 2 个条形列和 1 个线列
- c++ - 将 MATLAB 结构返回到 C++ 并访问元素
- javascript - 在导航栏中按下按钮时如何显示模态
- java - 在服务器上托管基于 java 的电报机器人
- java - java.lang.IncompatibleClassChangeError:类 org.springframework.session.hazelcast.PrincipalNameExtractor
- java - Java Money 获取汇率挂起
- windows - Windbg vtop 输出物理地址大于内存
- css - Angular,在 HTMLElement 上应用样式
- docker - 启动 docker 实例的问题