我想为用户实现一项功能,以上传文件(就像docs,ppts,文本文件一样)并保存到数据库,而另一个则可以查看从服务器获取的内容? 是否有任何框架或npm模块?
答案 0 :(得分:0)
Yes.
You can have one api endpoint to send files from your react app in the form of FormData
and recieve/handle it in your express app using Multer
. Then you can have another api endpoint to send file from your server and you can send the file using res.sendFile()
.
In your react app you need to access the file convert it into blob
and then into dataUrl
and then you can view it easily using that dataUrl
.