Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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
Node.js 从request.get body res上载节点条带文件_Node.js_File_Upload_Get_Stripe Payments - Fatal编程技术网

Node.js 从request.get body res上载节点条带文件

Node.js 从request.get body res上载节点条带文件,node.js,file,upload,get,stripe-payments,Node.js,File,Upload,Get,Stripe Payments,我正在使用一个Node env,我在其中发出请求。get从url检索一个文件,然后将其发送到Stripe。我得到一个错误,我的文件无效。在检索文件和发送文件之间有一个中间步骤,即我丢失了文件,但不确定是哪一个。我以前对本地文件使用fs.readFileSync,但现在不再使用它,因为我正在从服务器检索文件 Request.get(req.params.url, function (error, response, body) { if (!error && response.

我正在使用一个Node env,我在其中发出请求。get从url检索一个文件,然后将其发送到Stripe。我得到一个错误,我的文件无效。在检索文件和发送文件之间有一个中间步骤,即我丢失了文件,但不确定是哪一个。我以前对本地文件使用fs.readFileSync,但现在不再使用它,因为我正在从服务器检索文件

Request.get(req.params.url, function (error, response, body) {
  if (!error && response.statusCode == 200) {
    Stripe.fileUploads.create({
      purpose: 'identity_document',
      file: {
        data: body, // missing a step before sending it off
        name: 'file.png',
        type: 'application/octet-stream'
      }
    }, function(err, fileUpload) {
      if (err) {
        console.error(JSON.stringify(err));
        return res.error(err);
      }
      console.log(JSON.stringify(fileUpload));
    });
    // Continue with your processing here.
  }
});
这是我从Stripe得到的错误

code=141, type=StripeInvalidRequestError, rawType=invalid_request_error, code=undefined, param=file, message=We don't currently support that file type. Try uploading a file with one of the following mimetypes: image/jpeg, image/png, detail=undefined, type=invalid_request_error, message=We don't currently support that file type. Try uploading a file with one of the following mimetypes: image/jpeg, image/png

更改
file.type
application/octet-stream
更改为
image/png

更改
file.type
application/octet-stream
更改为
image/png

我想您需要将mimetime更改为,
类型:image/png
而不是当前类型:
'application/octet stream'
我想您需要将mimetime更改为,
类型:image/png
而不是当前类型:
'application/octet stream'