In android studio I used this code to convert image to byte array and send to server:
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] byteArrayImage = baos.toByteArray();
String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);
ServerService.sendProfileImage(encodedImage);
In node-js back-end I use this code to write data to file:
let imageBuffer = new Buffer.from(data.info, 'Base64');
fs.writeFile(fd, imageBuffer, (err, written) => {
if(err) {
callBack(err);
return;
} else{
fs.close(fd, () => {
callBack(null);
return;
});
}
})
Note: back-end works perfect with browser and saved images show correctly, > no problem; Android data is saved too, but image is not in correct format.
But some thing is wrong and Image is not a valid file.