Javascript 直接将缓冲区上载到Google云存储
我从第三方供应商处获取PDF文档作为Javascript 直接将缓冲区上载到Google云存储,javascript,node.js,google-api,google-cloud-storage,google-api-client,Javascript,Node.js,Google Api,Google Cloud Storage,Google Api Client,我从第三方供应商处获取PDF文档作为arraybuffer。我想直接将arraybuffer上传到Google存储,而不创建文件的本地副本 const axios = require('axios'); const google_storage = new Storage({ keyFilename: 'path_to_keyFilename' }); const upload_file = async (req, res, next) => { try { let fetc
arraybuffer
。我想直接将arraybuffer
上传到Google存储,而不创建文件的本地副本
const axios = require('axios');
const google_storage = new Storage({ keyFilename: 'path_to_keyFilename' });
const upload_file = async (req, res, next) => {
try {
let fetching_result = await axios({
method: 'get',
url: 'PDF_document_url',
responseType: 'arraybuffer'
});
let upload_result = await google_storage.bucket('bucket_name').upload(fetching_result.data);
return res.status(200).json(upload_result.data);
} catch (error) {
console.log('ERROR: ', error);
return res.status(400).json(error);
}
}
我正在使用@googlecloud/storage
包上传文件。但是当我将arraybuffer
传递给它时,我得到了以下错误:
错误:TypeError[ERR\u INVALID\u ARG\u VALUE]:参数“path”必须是不带空字节的字符串或Uint8Array。
收到您能提供更大的堆栈跟踪吗?更重要的是,请包括您正在使用的代码。例如,这是否试图使用
Bucket.upload
、File.save
、File.createWriteStream
等?你完全正确。我更新了我的问题。我尝试使用Bucket.upload()
。