Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 直接将缓冲区上载到Google云存储_Javascript_Node.js_Google Api_Google Cloud Storage_Google Api Client - Fatal编程技术网

Javascript 直接将缓冲区上载到Google云存储

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

我从第三方供应商处获取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 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()