我有一个firebase功能:
//Functions and firestore requirements are here
exports.saveData = functions.https.onRequest(async (req, res) => { console.log("Data received") const busboy = new Busboy({headers: req.headers}); const fields = {} const uploads = {}
//Push fields that are not file in fields busboy.on('field', (fieldname, val) => { console.log(Processed field ${fieldname}: ${val}.
); fields[fieldname] = val; }); //Push files in uploads busboy.on('file', (fieldname, file, filename) => { console.log('File :', file); const filepath = path.join(tmpdir, filename); uploads[fieldname] = filepath; }); busboy.on('finish', () => { console.log(uploads) console.log(fields) db.collection("a_collection").add({ a: fields.a, b: fields.b, file: "Help ! From the client, I send an image. Which value do I need to save ?" }) .then(function () { res.send("Data is saved") }) .catch(function (error) { res.status(400).send(error) console.error("Error :" + error) }) });
busboy.end(req.rawBody);
}) 运行代码段展开摘要
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。