这是reactnative的代码
uploadImage(imageuri){
let formData = new FormData();
let file = {uri: imageuri,type:'multipart/form-data',name:'image.png'};
formData.append('files',file);
fetch('http://127.0.0.1:8080/image',{
method:'POST',
headers:{
'Content-Type':'multipart/form-data',
},
body:fromData,
})
.then((response)=>response.text())
.then((responseData)=>{
console.log('responseData',responseData);
})
.catch((error)=>{console.error('error',error)});
}
后端 express
app.post('/image',function(req,res){后面不知道如何处理,才能保存到数据库或者保存到本地
https://github.com/expressjs/...
https://cnodejs.org/topic/564...
You can refer to the link above and use multer
Files are generally not saved to the database
Backend express
Print req.body and see if req.body.files has a value. This value is an object that contains information about the file you uploaded, file name, size, etc., then extract it and save it to the file you want to save. folder.
formidable middleware, the bottom layer of express is implemented using it. Here are the official examples.
soonfy