Imagepickerweb - A picker with which you can pick images and videos from your Flutter web app

Overview

ImagePickerWeb

Issues Stars Pub Version Flutter Web CI

This Web-Plugin allows Flutter Web to pick images (as File, Widget or Uint8List) and videos (as File or Uint8List). Many thanks goes to AlvaroVasconcelos for the implementation of picking images in his plugin: flutter_web_image_picker

ExampleGif

Disclaimer for Videos

  • Till now [Mar. 2020] it's not possible (due to security reasons) to play a local video file (see also video_player_web). But you can retreive the file and upload them somewhere and play it as a network source.

Getting Started

Add image_picker_web to your pubspec.yaml:

image_picker_web: any

Picking Images

Pick an image

Load image as Image.memory Widget:

Image? fromPicker = await ImagePickerWeb.getImageAsWidget();

Load image as bytes:

Uint8List? bytesFromPicker = await ImagePickerWeb.getImageAsBytes();

Load image as and html.File object :

html.File? imageFile = await ImagePickerWeb.getMultiImagesAsFile();

Pick multiple images

Load images as a List<Image> :

List<Image>? fromPicker = await ImagePickerWeb.getMultiImagesAsWidget();

Load images as bytes :

List<Uint8List>? bytesFromPicker = await ImagePickerWeb.getMultiImagesAsBytes();

Load images as List<html.File> objects :

List<html.File> imageFiles = await ImagePickerWeb.getMultiImagesAsFile();

How do I get all Informations out of my Image/Video (e.g. Image AND File in one run)?

Besides the standard getImage() or getVideo() methods you can use the getters:

  • getImageInfo or
  • getVideoInfo to acheive this.

Full Example

import 'dart:html' as html;
 
import 'package:mime_type/mime_type.dart';
import 'package:path/path.dart' as Path;
import 'package:image_picker_web/image_picker_web.dart';
import 'package:flutter/material.dart';

 html.File _cloudFile;
 var _fileBytes;
 Image _imageWidget;
 
 Future<void> getMultipleImageInfos() async {
    var mediaData = await ImagePickerWeb.getImageInfo;
    String mimeType = mime(Path.basename(mediaData.fileName));
    html.File mediaFile =
        new html.File(mediaData.data, mediaData.fileName, {'type': mimeType});

    if (mediaFile != null) {
      setState(() {
        _cloudFile = mediaFile;
        _fileBytes = mediaData.data;
        _imageWidget = Image.memory(mediaData.data);
      });
    }
  }

With getMultipleImageInfos() you can get all three available types in one call.

Picking Videos

To load a video as html.File do:

html.File? videoFile = await ImagePickerWeb.getVideoAsFile();

To load a video as Uint8List do:

Uint8List? videoData = await ImagePickerWeb.getVideoAsBytes();

Reminder: Don't use Uint8List retreivement for big video files! Flutter can't handle that. Pick bigger sized videos and high-resolution videos as html.File !

After you uploaded your video somewhere hosted, you can retreive the network url to play it.

MediaInfos

  • The methods getVideoInfo and getImageInfo are also available and you can use them to retreive further informations about your picked source.
Comments
  • Not receiving return after upload file window closed

    Not receiving return after upload file window closed

    Hi,

    After calling await ImagePickerWeb.getImage(outputType: ImageType.widget); and closing the file upload window, or pressing back on the smartphone, there is not a return from this call. I believe that a null was expected, so that I can dismiss a loadbar or anything like this on the page.

    Tested on chrome and firefox.

    Thanks,

    bug Stale 
    opened by VictorHomsi 15
  • ImagePickerWeb.getImage(outputType: ImageType.file);

    ImagePickerWeb.getImage(outputType: ImageType.file);

    Sorry man I try to use you lib but when I try to get file name from picked file I got a problem. The result html.File contains "name" property but this contain only the filename and not the full path, also the "relativePath" is always empty.

    Stale 
    opened by carmas123 7
  • iOS build issue which image_picker_web in pubspec.yaml

    iOS build issue which image_picker_web in pubspec.yaml

    First, thanks so much for the plugin. This will become more popular as flutter web becomes more common.

    Currently I have: image_picker_web: ^1.0.9 in my pubspec.yaml file.

    When building for iOS, I get the following error:

    [ios/.symlinks/plugins/image_picker_web/example] flutter pub get
    Running "flutter pub get" in example...                         
    Cannot open file, path = '/Users/username/.pub-cache/global_packages/image_picker_web_example/pubspec.lock' (OS Error: No such file or directory, errno = 2)
    pub get failed (66; Cannot open file, path = '/Users/username/.pub-cache/global_packages/image_picker_web_example/pubspec.lock' (OS Error: No such file or directory, errno = 2))
    exit code 66
    

    Since iOS isn't supported by this plugin, I took out all references in my code to the image_picker_web package, but I still get the error. The only way to avoid it is to comment out image_picker_web: ^1.0.9 in my pubspec.yaml and run 'flutter pub get'

    I was hoping to use the kIsWeb boolean to decide whether or not to use image_picker or image_picker_web package... but it looks like when image_picker_web is in the pubspec.yaml file, the project can't be built for iOS.

    Just to be clear, I'm not looking for any functionality for ios... I'm just hoping to be able to build with the package in the pubspec file. (and then, avoid that code with the kIsWeb boolean.

    Any help would be appreciated.

    no-issue-activity Stale 
    opened by wterrill 7
  • File Type

    File Type

    Have you got plans to have the image to be as file type File?

    The mobile version does this, and Firebase Storage Upload requires a File, not an Image.

    opened by jobsyNZ 6
  • Meta data path returns blank

    Meta data path returns blank

    When attempting to use the metadata path, all I ever get is blank

      Image fromPicker = await ImagePickerWeb.getImage(outputType: ImageType.widget);
      var meta = await ImagePickerWeb.getImageInfo;
      print('meta.path = ' + meta.filePath); // prints 'meta.path = '
    

    Am I missing something?

    EDIT: flutter information:

    >flutter doctor -v
    [√] Flutter (Channel beta, v1.17.0, on Microsoft Windows [Version 10.0.18362.778], locale en-CA)
        • Flutter version 1.17.0 at C:\development\flutter
        • Framework revision d3ed9ec945 (2 weeks ago), 2020-04-06 14:07:34 -0700
        • Engine revision c9506cb8e9
        • Dart version 2.8.0 (build 2.8.0-dev.18.0 eea9717938)
    
    [√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
        • Android SDK at C:\Users\danbm\AppData\Local\Android\sdk
        • Platform android-29, build-tools 28.0.3
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web
        • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
    
    [√] Android Studio (version 3.5)
        • Android Studio at C:\Program Files\Android\Android Studio
        • Flutter plugin version 42.0.1
        • Dart plugin version 191.8593
        • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
    
    [√] Connected device (2 available)
        • Chrome     • chrome     • web-javascript • Google Chrome 80.0.3987.163
        • Web Server • web-server • web-javascript • Flutter Tools
    
    • No issues found!
    
    opened by dmacattack 5
  • Picking and uploading videos

    Picking and uploading videos

    The README for this package states:

    Don't use Uint8List retreivement for big video files! Flutter can't handle that. Pick bigger sized videos and high-resolution videos as html.File !
    

    So that indicates we need to use html.File? videoFile = await ImagePickerWeb.getVideoAsFile();.

    However, in Flutter Web we can't use MultipartFile.fromPath() to upload (because there is no path available) since we can't use dart.io. So we have to use MultipartFile.fromBytes() to upload. So this means for larger files (or any video file?) we have to convert html.File back to Uint8List, correct? So how do we do that?

    Please correct any of these points if I'm wrong. Thanks!

    documentation 
    opened by blackbeario 4
  • Cannot run / build for web

    Cannot run / build for web

    [🔴] × flutter build web
    
    💪 Building with sound null safety 💪
    
    Target dart2js failed: Exception: /home/praharshb/snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_for_web-2.1.4/lib/image_picker_for_web.dart:246:23:
    Error: 'is' can't be used as an identifier because it's a keyword.
          if (!_completer.is Completed && files != null) {
                          ^^
    /home/praharshb/snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_for_web-2.1.4/lib/image_picker_for_web.dart:246:26:
    Error: Expected ')' before this.
          if (!_completer.is Completed && files != null) {
                             ^^^^^^^^^
    /home/praharshb/snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_for_web-2.1.4/lib/image_picker_for_web.dart:246:23:
    Error: The getter 'is' isn't defined for the class 'Completer<PickedFile>'.
     - 'Completer' is from 'dart:async'.
     - 'PickedFile' is from 'package:image_picker_platform_interface/src/types/picked_file/html.dart'
     ('/home/praharshb/snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_platform_interface-2.4.1/lib/src/types/picked_file/html.dart').
          if (!_completer.is Completed && files != null) {
                          ^^
    /home/praharshb/snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_for_web-2.1.4/lib/image_picker_for_web.dart:248:42:
    Error: Property 'first' cannot be accessed on 'List<File>?' because it is potentially null.
     - 'List' is from 'dart:core'.
     - 'File' is from 'dart:html'.
              html.Url.createObjectUrl(files.first),
                                             ^^^^^
    Error: Compilation failed.
    
    
    Compiling lib/main.dart for the Web...                             10.6s
    Exception: Failed to compile application for the Web.
    
    opened by praharshbhatt 4
  • image file are corrupted

    image file are corrupted

    I used the plugin. And I choose this html.File mediaFile = new html.File(mediaData.data, mediaData.fileName, {'type': mimeType})

    from Full Example in README

    And I uploaded to Firebase Storage but image file was broken same person is here https://stackoverflow.com/questions/60719724/flutter-web-upload-to-firestore

    no-issue-activity Stale 
    opened by shinriyo 4
  • getImage with 2 types at the same time

    getImage with 2 types at the same time

    Hello

    I'd like to getImage

        Image fromPicker = await ImagePickerWeb.getImage(outputType: ImageType.widget);
    

    and

        Uint8List bytesFromPicker =
            await ImagePickerWeb.getImage(outputType: ImageType.bytes);
    

    at the same time

    is is possible?

    Because, I wrote both of them. it open dialogs 2times.

    opened by shinriyo 4
  • Compiler error in Android/iOS(DartVM)

    Compiler error in Android/iOS(DartVM)

    I want to use both image_picker and image_picker_web. It work in flutter web. But native platform error.

    Compiler message:
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_web-1.0.8/lib/image_picker_web.dart:6:8: Error: Not found: 'dart:html'
    import 'dart:html' as html;
           ^
    
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_web-1.0.8/lib/src/web_image_picker.dart:2:8: Error: Not found: 'dart:html'
    
    import 'dart:html' as html;
    
           ^
    
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.1/lib/src/browser_client.dart:6:8: Error: Not found: 'dart:html'
    
    import 'dart:html';
    
           ^
    
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_web-1.0.8/lib/image_picker_web.dart:32:10: Error: Type 'html.File' not found.
    
      Future<html.File> _pickFile(String type) async {
    
             ^^^^^^^^^
    
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.1/lib/src/browser_client.dart:34:18: Error: 'HttpRequest' isn't a type.
    
      final _xhrs = <HttpRequest>{};
    
                     ^^^^^^^^^^^
    Running pod install...                                              2.8s
    Building macOS application...
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_web-1.0.8/lib/image_picker_web.dart:33:16: Error: 'FileUploadInputElement' isn't a type.
        final html.FileUploadInputElement input = html.FileUploadInputElement();
                   ^^^^^^^^^^^^^^^^^^^^^^
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_web-1.0.8/lib/image_picker_web.dart:33:47: Error: Method not found: 'FileUploadInputElement'.
        final html.FileUploadInputElement input = html.FileUploadInputElement();
                                                  ^^^^^^^^^^^^^^^^^^^^^^
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_web-1.0.8/lib/src/web_image_picker.dart:7:16: Error: 'FileUploadInputElement' isn't a type.
        final html.FileUploadInputElement input = html.FileUploadInputElement();
                   ^^^^^^^^^^^^^^^^^^^^^^
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_web-1.0.8/lib/src/web_image_picker.dart:7:47: Error: Method not found: 'FileUploadInputElement'.
        final html.FileUploadInputElement input = html.FileUploadInputElement();
                                                  ^^^^^^^^^^^^^^^^^^^^^^
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_web-1.0.8/lib/src/web_image_picker.dart:12:20: Error: Method not found: 'FileReader'.
        final reader = html.FileReader();
                       ^^^^^^^^^^
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_web-1.0.8/lib/src/web_image_picker.dart:28:16: Error: 'FileUploadInputElement' isn't a type.
        final html.FileUploadInputElement input = html.FileUploadInputElement();
                   ^^^^^^^^^^^^^^^^^^^^^^
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_web-1.0.8/lib/src/web_image_picker.dart:28:47: Error: Method not found: 'FileUploadInputElement'.
        final html.FileUploadInputElement input = html.FileUploadInputElement();
                                                  ^^^^^^^^^^^^^^^^^^^^^^
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_web-1.0.8/lib/src/web_image_picker.dart:33:20: Error: Method not found: 'FileReader'.
        final reader = html.FileReader();
                       ^^^^^^^^^^
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.1/lib/src/browser_client.dart:58:34: Error: 'Blob' isn't a type.
          var blob = xhr.response as Blob ?? Blob([]);
                                     ^^^^
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.1/lib/src/browser_client.dart:46:15: Error: The method 'HttpRequest' isn't defined for the class 'BrowserClient'.
     - 'BrowserClient' is from 'package:http/src/browser_client.dart' ('../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.1/lib/src/browser_client.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'HttpRequest'.
        var xhr = HttpRequest();
                  ^^^^^^^^^^^
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.1/lib/src/browser_client.dart:58:42: Error: The method 'Blob' isn't defined for the class 'BrowserClient'.
     - 'BrowserClient' is from 'package:http/src/browser_client.dart' ('../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.1/lib/src/browser_client.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'Blob'.
          var blob = xhr.response as Blob ?? Blob([]);
                                             ^^^^
    ../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.1/lib/src/browser_client.dart:59:20: Error: The method 'FileReader' isn't defined for the class 'BrowserClient'.
     - 'BrowserClient' is from 'package:http/src/browser_client.dart' ('../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.1/lib/src/browser_client.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'FileReader'.
          var reader = FileReader();
                       ^^^^^^^^^^
    ../../../development/flutter/packages/flutter_web_plugins/lib/src/plugin_registry.dart:29:5: Error: Method not found: 'webOnlySetPluginHandler'.
        ui.webOnlySetPluginHandler(_binaryMessenger.handlePlatformMessage);
        ^^^^^^^^^^^^^^^^^^^^^^^
    
    
    opened by abc873693 4
  • Is it possible to get Image and File?

    Is it possible to get Image and File?

    Hi, I am using this library on a form, I would like to show the Image widget when the user selects the image (I've accomplished this), but when I submit the form I need the File info to send it to Firebase and it seems the only way to get both is requesting the image twice to the user, which is kind of annoying.

    Thanks in advance,

    opened by clus90 4
Releases(3.0.0)
  • 3.0.0(Nov 21, 2022)

    • [BREAKING CHANGES] Removed deprecated methods getImage, getMultiImages and getVideo
    • Added methods getMultiVideosAsBytes, getMultiVideosAsFile
    Source code(tar.gz)
    Source code(zip)
  • 2.1.1(Mar 22, 2022)

    2.1.1 - [22/03/2022]

    • Updated example project to null safety.
    • Fixed potential issue with null value for methods getImageInfo, getVideoAsBytes and getVideoInfo.
    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(Dec 14, 2021)

    2.1.0 - [14/12/2021]

    • Deprecated getImage, getMultiImages and getVideo methods.
    • Added methods getImageAsBytes, getImageAsWidget, getImageAsFile, getMultiImagesAsBytes, getMultiImagesAsWidget, getMultiImagesAsFile, getVideoAsFile and getVideoAsBytes (#29)
    Source code(tar.gz)
    Source code(zip)
  • 2.0.3+1(Aug 9, 2021)

  • 2.0.3(Jun 15, 2021)

  • 2.0.2(Apr 26, 2021)

  • 2.0.1(Apr 3, 2021)

    2.0.1 - [30/03/2021]

    • Fixed FutureOr<Map<String, dynamic>> cast

    2.0.0 - [27/03/2021]

    • Breaking Changes: migrated code to nullsafety
    • Removed deprecated properties

    1.1.3 - [06/10/2020]

    • Added toJson method to MediaInfo
    • Fixed getImageInfo and getVideoInfo
    • Updated example/main.dart

    1.1.2+1 - [06/10/2020]

    • Fixed pickImage and pickVideo

    1.1.2 - [06/10/2020]

    • Fixed compatibility with iOS web browser

    1.1.1 - [02/10/2020]

    • Upgraded minimum sdk to >=2.7.0
    • Added new ImageType.mediaInfo
    • Made some code refacto

    1.1.0+2 - [01/09/2020]

    • Update README.md

    1.1.0+1 - [01/09/2020]

    • Format code to dartfm standard
    • Added comments

    1.1.0 - [01/09/2020]

    • Retake of the discontinued package image_picker_web
    • Refacto of method getImage
    • Added method getMultiImages to allow multi-image selection
    • Added a few comments for documentation generations
    Source code(tar.gz)
    Source code(zip)
  • 1.0.9(Mar 27, 2021)

Owner
Rebar Ahmad
Software-Engineer | - Flutter - Firebase - Ionic/Angular - GraphQL - MongoDB - Node/Express - Java Spring Boot - Docker / Kubernetes / HELM
Rebar Ahmad
In this repo you will see how to pick images from the image library and also, see how to store the selected images on Firebase.

flutterimageapp Flutter Tutorial - Upload Images using Firebase Storage. Flutter Tutorial - Upload Images using Firebase Storage Video series can be w

Whatsupcoders 60 Nov 4, 2022
Memebaaz is a video/images sharing app, Anyone can share short videos and images through app, the media will go through admin's approval.

MemeBaaz - Memes & Short Videos App Memebaaz is a Video/images Sharing App, Anyone can share short videos and images through app, the media will go th

Rakesh K. 18 Nov 14, 2022
camilo velandia 69 Dec 30, 2022
An app to pick, upload and display images from camera and gallery with size and extension constraints.

image_uploader A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

Ehmad Saeed⚡ 4 Mar 7, 2022
Stories like in Instagram, each story can include multiple images and videos. Package supports video, titles, preliminary caching.

flutter_instagram_stories A Flutter package for displaying stories just like Whatsapp & Instagram. Built-in groups (multiple stories with one icon), c

Alex Awaik 125 Dec 9, 2022
Download files from Firebase Storage with Flutter. List all images, videos, or other files from Firebase and download them.

Flutter Tutorial - Download Files From Firebase Storage Download files from Firebase Storage with Flutter. List all images, videos, or other files fro

Johannes Milke 28 Dec 4, 2022
Flutter plugin that saves images and videos to devices gallery

Gallery Saver for Flutter Saves images and videos from network or temporary file to external storage. Both images and videos will be visible in Androi

Carnegie Technologies 131 Nov 25, 2022
A flutter date time picker inspired by flutter-cupertino-date-picker

Flutter Datetime Picker (Pub) flutter_datetime_picker A flutter date time picker inspired by flutter-cupertino-date-picker you can choose date / time

null 0 Nov 30, 2021
Color picker for Flutter, based on the Google Docs color picker.

Material ColorPicker Color picker for Flutter, based on the Google Docs color picker. Getting Started You can embed into your material app or use it o

Razvan Lung 103 Oct 30, 2022
Form builder image picker - Form builder image picker for flutter

form_builder_image_picker Field for picking image(s) from Gallery or Camera for

Ferri Sutanto 0 Jan 28, 2022
Nepali date picker - Material Style Date Picker with Bikram Sambat(Nepali) Calendar Support

Nepali Date Picker + Calendar Material and Cupertino Styled Date Picker, Date Range Picker and Calendar with Bikram Sambat(Nepali) Support. Nepali Dat

Sarbagya Dhaubanjar 35 Jan 3, 2023
Display images flutter - Simple app to display images in flutter

Display Images In Flutter Simple app to display images in a flutter. In this dem

Manish Ahire 1 Jan 29, 2022
Rooftop - A photos and videos application which is able to show curated content from Pexel database on the press of a button

rooftop RoofTop is a photos and videos application which is able to show curated

null 2 Feb 7, 2022
Flutter APP which fetches data from YouTube & Play Videos!😉

YouTube Video Player YouTube Video Player is built in FLUTTER ?? & DART ?? Motivation As this project uses YouTube Data API v3, motivation for this pr

Abhishek Rajendra Wagh 7 Apr 12, 2022
Material color picker, you can customize colors. Selection in two step, first main color and after shades.

Flutter Material Color Picker Material Color picker is a Flutter widget, that can be customizable. By default, it's Material Colors, but you can defin

Jean-Charles Moussé 70 Nov 25, 2022
It's a universal app template to have a great animated splash screen and liquid slider. Just change the animation if you want (rive) and change the images or colours according to your app.

liquid A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this i

Zikyan Rasheed 28 Oct 7, 2022
dos downloader app is developed for downloading video. You can download video from YouTube and Facebook. You can also play video on background

dosdownloader Dos downloader app is developed for downloading video. You can download video from YouTube and Facebook. You can also play video on back

Md Abir Ahsan Tahmim 1 Dec 8, 2021
Flutter package to show and pick country code

country list pick Flutter plugin to pick country with output name, code, dialcode and flag of country Usage To use this plugin, add country_list_pick

fiaz 69 Nov 13, 2022