【发布时间】:2019-08-20 13:08:40
【问题描述】:
我正在尝试发送包含(原始)文件的 POST 表单,这些文件位于谷歌云存储桶中
此代码在 firebase 云函数中运行 - 我不想将存储文件下载到云函数实例然后通过表单上传(可行),而是直接将表单传递给 Stream
async function test() {
const rp = require('request-promise');
const path = require('path');
const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
const bucketName = 'xxx';
const bucket = storage.bucket(bucketName);
const fileAPath = path.join('aaa', 'bbb.jpg');
let formData = {
fileA: bucket.file(fileAPath).createReadStream(),
};
return rp({
uri: uri,
method: 'POST',
formData: formData,
});
}
如果我们先下载文件(到云函数实例上的临时文件)然后使用fs.createReadStream(fileAPath_tmp),则 POST 会按预期工作
使用bucket.file(fileAPath).createReadStream() 使用上面的代码(无临时下载)时,POST 失败(即端点没有以相同的方式接收文件,如果有的话)
【问题讨论】:
标签: node.js firebase google-cloud-storage