0
 1.final formData = FormData.fromMap({
  'file': await MultipartFile.fromFile(
    file.path,
    filename: fileName,
    contentType: MediaType.parse('video/mp4'),
  ),
});

2.final response = await dio.put<dynamic>(endpoint, data: formData, options: Options(contentType: 'video/mp4'));

  return response.data;

above I changed the content type to video/mp4 (I tried both ways separately) but I am still getting multipart/form-data; boundary=--dio-boundary-3846454268 After changing content type is should also change to video/mp4 in S3 bucket console, it didn't change and because of that I am getting corrupted file in S3 bucket although I successfully uploaded a video. Looks like default content type in Multipart request is not changing although I tried both ways.

Any ideas how to change the default content type of Dio Multipart request in Flutter? Thanks

  • According to https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html you shouldn't be using a multipart form as the body. Why don't you use the 'official' S3 package? https://pub.dev/packages/amplify_storage_s3 – Richard Heap Aug 08 '23 at 16:28
  • Thank you for the answer, I just have a presigned aws url to upload file. How can I use that url with S3 official package? – Ilyos Ibrokhimov Aug 09 '23 at 05:38
  • See second answer here: https://stackoverflow.com/questions/62648883/flutter-dio-upload-image-using-binary-body-with-dio-package - skip wrapping the content in a multipart for and just send it. (If it's small enough you can simply read it into memory and then send the contents of the byte buffer.) – Richard Heap Aug 09 '23 at 10:37

0 Answers0