Flutter imagepicker.pickvideo return jpg

1,518

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.

Share:
1,518
sungchan
Author by

sungchan

Updated on December 25, 2022

Comments

  • sungchan
    sungchan over 1 year

    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?

  • sungchan
    sungchan over 3 years
    i tried, but when i convert it to file it still returns jpg
  • Dan Gerchcovich
    Dan Gerchcovich over 3 years
    try the other package I suggested then
  • Dan Gerchcovich
    Dan Gerchcovich over 3 years
    Just try it for now, and if it works for you it's a temporary workaround
  • Dan Gerchcovich
    Dan Gerchcovich over 3 years
    can you check the result by the way of the returned file. So try to get the path of the resulting video file, and print(). Check to see if the file returned from the package image_picker is correct (as in it's a video file and not an image file), or it's your own code. Usually it's a bug in your code.
  • sungchan
    sungchan over 3 years
    thank you for advising to use getVideo.. and functionally it works, but i got confused a few seconds because it returns jpg file but when i saw this file in firebase it recognized as a video.. im just curios why it names has include 'jpg' so i thought it was it's extension