Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't upload on web, "MultipartFile is only supported where dart:io is available." #7

Closed
esDotDev opened this issue Mar 4, 2021 · 6 comments
Assignees

Comments

@esDotDev
Copy link

esDotDev commented Mar 4, 2021

On Flutter Web, I'm calling cloudStorage.multiUpload and getting:

Error: Unsupported operation: MultipartFile is only supported where dart:io is available.
    at Object.throw_ [as throw] (http://localhost:52896/dart_sdk.js:5342:11)

Is this expected? Seems like this might be an issue in Dio, so not sure exactly where to log it.

@djade007 djade007 self-assigned this Mar 5, 2021
@esDotDev
Copy link
Author

esDotDev commented Mar 5, 2021

Created an issue here: cfug/dio#1067

This might be a local workaround you could do?
https://stackoverflow.com/questions/63314063/upload-image-file-to-strapi-flutter-web

@djade007
Copy link
Owner

djade007 commented Mar 5, 2021

@esDotDev I'm looking into this now. There was an initial plan to switch to https://pub.dev/packages/http instead of Dio

@djade007
Copy link
Owner

djade007 commented Mar 5, 2021

Update:

I was able to get it to work on web this way:

try {
  final res = await cloudinary.uploadFile(
    CloudinaryFile.fromByteData(
      ByteData.sublistView(
        await _pickedFile.readAsBytes(),
      ),
      identifier: _pickedFile.path.split('/').last,
    ),
  );
  print(res);
} catch (e, s) {
  print(e);
  print(s);
}

@esDotDev
Copy link
Author

esDotDev commented Mar 5, 2021

Amazing, thanks!

@esDotDev esDotDev closed this as completed Mar 5, 2021
@djade007
Copy link
Owner

djade007 commented Mar 6, 2021

@esDotDev I have published a new version 0.7.0

  • It now uses http instead of Dio
  • Your initial code should also work on web, you don't have to use the code example I provided above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants