【发布时间】:2018-05-09 07:26:55
【问题描述】:
我正在使用第三方 api,它以二进制媒体数据格式返回图像。获取此数据后,我想将其上传到 Google Cloud Storage。为此,我需要将此数据转换为 Buffer。我尝试了很多次,但都失败了。
我正在使用NodeJS,npm请求模块调用api将图像保存到谷歌云存储。
代码如下:
var binaryData = data;
var bufferData = new Buffer(data);
request({
method: "POST",
url: '/endpoint/upload',
headers: {
'cache-control': 'no-cache',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
},
formData: {
filename: {
value: fileBase64,
options: {
filename: 'test.jpg',
contentType: 'image/jpeg'
}
},
}
}, function(err, response, body){
console.log(body);
})
【问题讨论】:
标签: node.js base64 buffer google-cloud-storage binary-data