所以我使用Axios将文件从一台服务器发送到另一台服务器,一个是应用程序后端,另一个是区块链服务器。我将文件发送到哪里:router.post("/acme/:id", auth, async (req, res) => { var formData = new FormData(); console.log(req.files.file) formData.append("image", req.files.file.data); var Response; try { Response = await axios.post(BC_SERVER + "acmeDataFileUpload", { id: req.params.id, data: formData, headers: { 'Content-Type': 'multipart/form-data' } }); } catch (error) { console.log("Error BlockChain"); } try { res.status(201).send("ok"); } catch (e) { res.status(500).send(e); } });Axios 发送它的位置:app.post('/acmeDataFileUpload', async (req, res) => { const id_owner = req.body.id; console.log(req.body) const file = req.body.data; const fileName = id_owner; const filePath = 'files/' + fileName; console.log(fileName); file.mv(filePath, async (err) => { try { const fileHash = await addFile(fileName, filePath); fs.unlink(filePath, (err) => { if (err) console.log(err); }); const json = '{"dataType": "Object" , "local": "'+localServer+fileHash+'",' +'"ipfsServer": "'+ipfsServer+fileHash+'"}'; console.log(json); const obj = JSON.parse(json); res.status(201).send(obj); } catch (err) { console.log('Error : failed to download file'); console.log(err); return res.status(500).send(err); } });});基本上我在这里发送缓冲区,因为FormData不接受文件并告诉我source.on不是一个函数,我宁愿我的图像被发送到而不是,Axios真的让我感到困惑。req.filesreq.body
添加回答
举报
0/150
提交
取消