MultipartFile is only supported where dart:io is available

When I try to upload images from a web browser, I receive an exception: “Unsupported operation: MultipartFile is only supported where dart:io is available.

Environment I am currently using:

Flutter (Channel stable, 2.10.1, on macOS 11.4 20F71 darwin-x64, locale en-GB)
• Flutter version 2.10.1 at /Users/macbook/Documents/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision db747aa133 (3 months ago), 2022-02-09 13:57:35 -0600
• Engine revision ab46186b24
• Dart version 2.16.1
• DevTools version 2.9.2

Does anybody know what could the issue ?

Upvotes: 4

Views: 8040

Answers (1)

Nate Bosch
Nate Bosch

Reputation: 10935

You cannot use MultipartFile.fromPath in the browser because the browser does not give arbitrary access to the filesystem.

If you implement file picking using what is available in the browser you can create a MultipartFile from a String or from bytes in the browser.

Upvotes: 7

Related Questions