这是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...
可以參考上面的鏈接,使用multer
檔案的話一般不保存到資料庫
後端express
打印req.body,看看req.body.files有沒有值,這個值是一個對象,包含你上傳的文件相關信息,文件名,大小等,然後從中提取並存到你想存的資料夾。
formidable中間件,express底層就是用它實現的。以下是官方例子。
soonfy