3

I am using the POST method to upload video file from Flutter App using the Dio package. Vimeo's POST method first generates a link for us to upload the video to. The video is uploaded successfully most of the time. Every once in a while, it fails (like 1/10).

enter image description here

To Test if this is an issue on Vimeo's server I tried uploading the video from POSTMAN, 20/20 (all of them) times it uploaded successfully. So I am assuming there is something wrong with the DIO Package?

I have also posted this issue in the DIO's github issues: https://github.com/flutterchina/dio/issues/1535#issue-1328014439

Upload video code:

 if (url != null) {
    print('upload link is not null!');
    Strings.videoURL = url;
    print('upload url is <>:');
    print(Strings.videoURL);
    try {
      Dio uploadVideoDio = new Dio();
      uploadVideoDio.options.headers["authorization"] = dotenv.env['VIMEO_ACCESS_TOKEN'];
      uploadVideoDio.options.headers["content-type"] = "application/json";
      uploadVideoDio.options.headers["accept"] = "application/json";

      var formData = FormData.fromMap({
        "file_data": await MultipartFile.fromFile(file.path)
      });

     await uploadVideoDio.post(
        Strings.videoURL,
        data: formData,
        options: Options(
            followRedirects: false,
            responseType: ResponseType.json,
            validateStatus: (status) {
              print('status is :');
              print(status);
              // return status! < 500;
              if (status == 302) {
                uploadStatus = 'successful';
                return true;
              } else {
                return false;
              }
            }),
      );
      print('file upload called');
      print('upload status is ');
      print(uploadStatus);
      return uploadStatus;
    } on DioError catch (err) {
      print('error uploading actual video');
      print(err.toString());
      return uploadStatus;
    }
  } else {
    print('upload link is null');
    return uploadStatus;
  }

Here's an update

I got in touch with the Vimeo's support team and they are investigating the issue. Their response is that

The "POST" method is not very reliable and you should use the TUS resumable approach.

I am about to test the stability of the TUS method and will update this post afterwards

Manas
  • 3,060
  • 4
  • 27
  • 55

0 Answers0