How to send files with superagent

前端 未结 4 871
南笙
南笙 2021-01-03 03:46

So about a month ago I asked a question regarding superagent and sending files, but got no response at all. I would still like to find out how to do this as I enjoy using su

4条回答
  •  無奈伤痛
    2021-01-03 04:22

    Attach should work.
    Example using express/multer:

    client:

    superagent.post('http://localhost:3700/upload').attach('theFile',file);
    

    server:

     const storage = multer.memoryStorage();
     const upload = multer({ storage: storage });
     router.post("/upload", upload.single('theFile'), (req, res) => {
       debug(req.file.buffer);
       res.status(200).send( true );
       res.end();
     });
    

提交回复
热议问题