我正在尝试将文件上传到nanosets API。我将以下节点js函数上载到firebase,并尝试使用以下URL对其进行过度处理,例如使用正文中的文件(试图通过邮递员对此进行测试)
Node js函数如下:
exports.uploadFile = functions.https.onRequest((req, res) => {
cors(req, res, () => {
if (req.method !== "POST") {
return res.status(500).json({
message: "Not allowed"
});
}
const busboy = new Busboy({headers: req.headers});
let uploadData = null;
busboy.on("file", (fieldname, file, filename, encoding, mimetype) => {
const filepath = path.join(os.tmpdir(), filename);
uploadData = {modelId: '4bc54977-60cf-4415-a417-c39f1c18b83f', file: fs.createReadStream(filename), type: mimetype};
const options = {
url: 'https://app.nanonets.com/api/v2/OCR/Model/XXXXXXX-60cf-4415-a417-c39f1c18b83f/LabelFile/',
formData: uploadData,
headers: {
'Authorization': 'Basic ' + Buffer.from('tiOJNxuDbdl40lXXXXXXXXXXFTYbY' + ':').toString('base64')
}
};
request.post(options, function (err, httpResponse, body) {
if (err) {
console.log(err);
}
console.log(body)
});
});
busboy.on("finish", () => {
res.status(200).json({
message: "It worked!"
});
});
busboy.end(req.rawBody);
});
});
为什么我使用 firebase函数检查日志:日志,却得到以下结果:
2020-06-06T09:35:06.168774140Z D uploadFile:函数开始执行 2020-06-06T09:35:06.344Z我上传了File:invoice_4.pdf 2020-06-06T09:35:06.432Z我上载文件:FileStream { 2020-06-06T09:35:06.439Z E uploadFile:TypeError:source.pause不是一个函数
有人知道吗?如何将文件传递给纳米集?