Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MultipartFile is only supported where dart:io is available

Tags:

flutter

dart

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 ?

like image 423
Екатерина Новицкая Avatar asked Oct 20 '25 11:10

Екатерина Новицкая


1 Answers

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.

like image 98
Nate Bosch Avatar answered Oct 23 '25 03:10

Nate Bosch