Node.js 从request.get body res上载节点条带文件
我正在使用一个Node env,我在其中发出请求。get从url检索一个文件,然后将其发送到Stripe。我得到一个错误,我的文件无效。在检索文件和发送文件之间有一个中间步骤,即我丢失了文件,但不确定是哪一个。我以前对本地文件使用fs.readFileSync,但现在不再使用它,因为我正在从服务器检索文件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.
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'