繁体   English   中英

从request.get body res上传节点条带文件

[英]Node Stripe file upload from request.get body res

我正在使用Node env,我正在发出请求。从网址中检索文件然后将其发送到Stripe。 我得到141错误,我的文件无效。 检索文件和发送它之间有中间步骤,我错过了但不确定哪个。 我曾经使用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.typeapplication/octet-stream更改为image/png

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM