【问题标题】:Stream from HTTPS to Google Cloud Bucket从 HTTPS 流式传输到 Google Cloud Bucket
【发布时间】:2017-06-23 10:16:42
【问题描述】:
是否可以将来自 Google Cloud 函数中 fetch api 的“ReadableStream”流式传输到存储桶中?
似乎 getReader() 从 fetch 的 http 响应返回一个。 createReadStream 和
createWriteStream();
localReadStream.pipe(remoteWriteStream);
应该将流从存储桶 => fs => fs 传输到存储桶(或不同存储桶中的新文件),但 AFAIK Cloud Functions 不允许本地文件访问,对吧?
一个如何从一个流到一个桶?
【问题讨论】:
标签:
google-cloud-storage
google-cloud-functions
【解决方案1】:
让它工作:
const fetch = require('node-fetch');
const Storage = require('@google-cloud/storage');
const CLOUD_BUCKET = 'MY_BUCKET_NAME'
const storage = Storage({
projectId: 'MY_PROJECT_NAME'
});
const bucket = storage.bucket(CLOUD_BUCKET);
fetch(url).then( response => {
let remoteWriteStream = bucket.file('zebra.png').createWriteStream();
response.body.pipe(remoteWriteStream);
})
基本上是管体本身。