是否可以流式传输" ReadableStream"从Google Cloud功能中的fetch
api到存储桶?
似乎getReader()从来自fetch的http响应中返回一个。 createReadStream和
createWriteStream();
localReadStream.pipe(remoteWriteStream);
假设来自bucket =>的管道流fs => fs to bucket(或不同存储桶中的新文件),但AFAIK Cloud Functions不允许本地文件访问,对吧?
如何从一个流传输到存储桶?
答案 0 :(得分:0)
让它发挥作用:
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);
})
基本上管道身体本身。