'How to send Video to a URL via REST in flutter using dio?

So I've been trying to send a video to a URL for a while now using dio client, but my issue is the fact that the video actually gets sent, but becomes unplayable when it's received at the server, and I don't know why that happens.

Below is the code block for the video upload functionality:

 uploadVideo(
      String? ownedBy, bool isVideoRequest, String fileType, File file) async {
    String fileName = file.path.split('/').last;
    String url =
        await getFileUploadUrl(ownedBy, isVideoRequest, fileName, fileType);

    FormData formData = FormData.fromMap({
      "file": await MultipartFile.fromFile(file.path),
    });
    var options = Options(
      method: 'PUT',
    );
    var response = await dioClient.put(url, data: formData, options: options,
        onSendProgress: (v, x) {
      print((v / x) * 100);
    });
    print(response.statusMessage);
    print(response.statusCode);
  }


Solution 1:[1]

You can try adding encoding type to options

Options(
  requestEncoder: (_, __) => file.readAsBytesSync()
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Muhtar