Need some help troubleshooting an HTTP request in Flutter using the PUT method sending an image file on the body to a NextCloud server via API.
As always, i tested sending the request via POSTMAN to see what's happening. It worked ok selecting "binary" in the body tab and selecting the image file.
The file is there as intended:
Moving to implement this on the Flutter app I'm using the code below:
_imageFile = Contains the image from camera or gallery.
RaisedButton(
color: Colors.blueAccent,
child: Text('enviar'),
onPressed: () async {
String base64Image = base64Encode(_imageFile.readAsBytesSync());
print(base64Image);
var client = http.Client();
var request = http.Request(
'PUT', Uri.parse('https://host123.com.br/remote.php/dav/files/82427565709/TOOP.jpeg'));
request.headers.addAll(
{HttpHeaders.authorizationHeader: 'Basic ODI0Mjc1NjU3MDk6Y2xlYW5uZXQ=', 'Content-Type': 'image/jpeg'});
request.body = base64Image;
var streamedResponse = await client.send(request);
client.close();
print('ok!');
},
),
The result on terminal:
I/flutter ( 8349): /9j/4AAQSkZJRgABAQEASABIAAD/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAABtbnRyUkdCIFhZWiAHzgACAAkABgAxAABhY3NwTVNGVAAAAABJRUMgc1JHQgAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLUhQICAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABFjcHJ0AAABUAAAADNkZXNjAAABhAAAAGx3dHB0AAAB8AAAABRia3B0AAACBAAAABRyWFlaAAACGAAAABRnWFlaAAACLAAAABRiWFlaAAACQAAAABRkbW5kAAACVAAAAHBkbWRkAAACxAAAAIh2dWVkAAADTAAAAIZ2aWV3AAAD1AAAACRsdW1pAAAD+AAAABRtZWFzAAAEDAAAACR0ZWNoAAAEMAAAAAxyVFJDAAAEPAAACAxnVFJDAAAEPAAACAxiVFJDAAAEPAAACAx0ZXh0AAAAAENvcHlyaWdodCAoYykgMTk5OCBIZXdsZXR0LVBhY2thcmQgQ29tcGFueQAAZGVzYwAAAAAAAAASc1JHQiBJRUM2MTk2Ni0yLjEAAAAAAAAAAAAAABJzUkdCIElFQzYxOTY2LTIuMQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWFlaIAAAAAAAAPNRAAEAAAABFsxYWVogAAAAAAAAAAAAAAAAAAAAAFhZWiAAAAAAAABvogAAOPUAAAOQWFlaIAAAAAAAAGKZAAC3hQAAGNpYWVogAAAAAAAAJKAAAA+EAAC2z2Rlc2MAAAAAAAAAFklFQyBodHRwOi8vd3d3LmllYy5jaAAAAAAAAAAAAAAAFklFQyBodHRwOi8vd3d3LmllYy5jaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABkZXNjAAAAAAAAAC5JRUMgNjE5NjY
I/flutter ( 8349): ok
The result on the Nextcloud server sending via APP:
Looks like there is something wrong with the encoding or the data that's being sent on the body. The file get "corrupted"
It is the same file on both tests.
** UPDATE **
After changing the body data to just the bytes, as suggested, without base64encoding. (Image Below)
Tried convert using .toString() method too, the file went to the server but stayed the same as before, looking corrupted.




request.bodyBytes