Answer the question
In order to leave comments, you need to log in
Passing base64 from flutter to express?
I get a photo in the emulator, transfer it to the server, but for some reason an empty body is displayed on the server...
###CLIENT###
saveImgToBase(File img, app) async{
sharedPreferences = await SharedPreferences.getInstance();
if (img == null) return;
String base64Image = base64Encode(img.readAsBytesSync());
var body={
"image": base64Image,
"name": app.id
};
await http.post('http://192.168.0.101:5000/api/driver/foto', body: body).then((res) {
print(res.body);
}).catchError((err) {
print(err);
});
}
app.post('/api/driver/foto',async (req,res)=>{
console.log(req.body); // ВОТ ТУТ ВЫВОДИТСЯ {} ХОТЯ ДОЛЖЕН ОБЬЕКТ
try{
var name = req.body.name;
var img = req.body.image;
var realFile = Buffer.from(img,"base64");
fs.writeFile(name, realFile, function(err) {
if(err)
console.log(err);
});
res.send("OK");
}catch(err){
res.status(422).json({error:"Не сохранилось в папку, напишите администратору."});
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question