I am trying to send an image to a node js rest api from a flutter app , and on the server the image is not being received ( It works fine on the web version but on the mobile the file is not being uploaded ) Multer is used for handling multipart/form-data on the server side and on the client side I am doing this

    var request = MultipartRequest(
    'PUT',
    Uri.parse(
      "URL",
    ));
request.headers['authorization'] = token;
request.headers['Content-Type'] = 'multipart/form-data';
request.files.add(MultipartFile(
  'userUrl',
  image.readAsBytes().asStream(),
  image.lengthSync(),
));

StreamedResponse res = await request.send();

image is a File object and I am using the http package but I also tried using dio and it's the same result .


Solution 1: ElVincitore

I found the problem , it was just that the mimetype is missing :

    String fileName = image.path.split('/').last;
final mimeTypeData =
    lookupMimeType(image.path, headerBytes: [0xFF, 0xD8]).split('/');
var request = MultipartRequest(
    'PUT',
    Uri.parse(
      "url",
    ));
request.headers['authorization'] = token;
request.headers['Content-Type'] = 'multipart/form-data';
request.files.add(await MultipartFile.fromPath('userUrl', image.path,
    contentType: MediaType(mimeTypeData[0], mimeTypeData[1])));

StreamedResponse res = await request.send();