uploadVideo method

Future<CloudinaryResponse> uploadVideo(
  1. String videoPath, {
  2. String? videoFilename,
  3. String? folder,
})

Implementation

Future<CloudinaryResponse> uploadVideo(String videoPath, {String? videoFilename, String? folder}) async {
  var timeStamp = DateTime.now().millisecondsSinceEpoch;

  var params = <String, dynamic>{};
  if (_apiKey == null) {
    throw Exception('apiKey and apiSecret must not be null');
  }

  params['api_key'] = _apiKey;

  // ignore: unnecessary_null_comparison
  if (videoPath == null) {
    throw Exception('videoPath must not be null');
  }
  var publicId = videoPath.split('/').last;
  publicId = publicId.split('.')[0];

  if (videoFilename != null) {
    publicId = videoFilename.split('.')[0];
  } else {
    videoFilename = publicId;
  }

  params['folder'] = folder;

  params['public_id'] = publicId;

  params['file'] = await MultipartFile.fromFile(videoPath, filename: videoFilename);
  params['timestamp'] = timeStamp;
  params['signature'] = getSignature(folder, publicId, timeStamp);

  var formData = FormData.fromMap(params);

  var dio = await getApiClient();
  var response = await dio.post('$_cloudName/video/upload', data: formData);
  try {
    return CloudinaryResponse.fromJsonMap(response.data);
  } on Exception catch (error, stacktrace) {
    debugPrint('Exception occured: $error stackTrace: $stacktrace');
    return CloudinaryResponse.fromError('$error');
  }
}