Flutter imagepicker.pickvideo return jpg

2k views Asked by At

I'm using this to return the video file but I got .jpg

Future<File> getVideo() async {
     var video = await ImagePicker.pickVideo(
          source: ImageSource.gallery);
      return video;
    }

I want to ImagePicker.pickVideo() return video file instead of .jpg file so I can upload this file to firebase, how can I achieve that?

1

There are 1 answers

5
Dan Gerchcovich On BEST ANSWER

I'm assuming that you're using the package: https://pub.dev/packages/image_picker

pickVideo() method has been decrecated, and you will need to replace these apis with getVideo()

As explained the repositories' documentation: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker

Write this:

final _picker = ImagePicker();
PickedFile video = await _picker.getVideo(...)

However I would suggest to use this package as an alternative: https://pub.dev/packages/flutter_document_picker

This package will allow you to select all videos on the device, including those taken from a users' Google Drive or iCloud providers. In this case write this:

FlutterDocumentPickerParams params = FlutterDocumentPickerParams(
      allowedUtiTypes: [
        'public.video',
        'public.mpeg',
        'public.mpeg-4-audio',
        'com.apple.protected-​mpeg-4-audio'
      ],
      allowedMimeTypes: [
        'video/mpeg',
        'video/x-flv',
        'video/mp4',
        'application/x-mpegURL',
        'video/quicktime',
        'video/x-msvideo',
        'video/x-ms-wmv',
        'video/ogg',
        'video/mp2t',
        'video/3gpp'
      ],
      invalidFileNameSymbols: ['/'],
    );

    return await FlutterDocumentPicker.openDocument(params: params);

You will need to make sure that the Mimes and Uti types for videos on iOS & Android are set correctly.