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

[Bug]: Share.shareXFiles doesn't work if XFile is created using File.fromData() #1188

Closed
7 tasks done
zache-fi opened this issue Oct 11, 2022 · 2 comments · Fixed by #1284
Closed
7 tasks done

[Bug]: Share.shareXFiles doesn't work if XFile is created using File.fromData() #1188

zache-fi opened this issue Oct 11, 2022 · 2 comments · Fixed by #1284
Labels
android enhancement New feature or request Hacktoberfest Issues taking part in Hacktoberfest share_plus Feature, Enhancement, Bug Fixes for Share Plus Plugin

Comments

@zache-fi
Copy link

Platform

Android 12

Plugin

share_plus

Version

5.0.0

Flutter SDK

3.3.4

Steps to reproduce

Steps to reproduce

1.) Load file from url
2.) Create new XFile using XFile.fromData()
3.) try to share created File object

Result

Sharing fails because XFile doesn't have path

Expected result
For cross platform support It should not matter how XFile has been created or wether object has path

Code Sample

import 'package:http/http.dart' as http;
import 'package:share_plus/share_plus.dart';
import 'package:cross_file/cross_file.dart';

url='https://upload.wikimedia.org/wikipedia/commons/a/a9/Example.jpg
response  = await http.get(Uri.parse(url));
XFile file = XFile.fromData(response.bodyBytes, name:'image.jpg', mimeType:'image/jpeg');
await Share.shareXFiles([file],text:"example");

Logs

E/flutter ( 5048): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:share_plus_platform_interface/method_channel/method_channel_share.dart': Failed assertion: line 111 pos 12: 'paths.every((element) => element.isNotEmpty)': is not true.
E/flutter ( 5048): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
E/flutter ( 5048): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
E/flutter ( 5048): #2      MethodChannelShare.shareFilesWithResult (package:share_plus_platform_interface/method_channel/method_channel_share.dart:111:12)
E/flutter ( 5048): #3      MethodChannelShare.shareXFiles (package:share_plus_platform_interface/method_channel/method_channel_share.dart:146:12)
E/flutter ( 5048): #4      Share.shareXFiles (package:share_plus/share_plus.dart:182:22)
E/flutter ( 5048): #5      CrossplatformShare.shareFiles (package:ajapaik_flutter_app/services/crossplatformshare.dart:34:19)
E/flutter ( 5048): <asynchronous suspension>

Flutter Doctor

[✓] Flutter (Channel stable, 3.3.4, on macOS 12.6 21G115 darwin-arm, locale en-FI)
    • Flutter version 3.3.4 on channel stable at /Users/kimmovirtanen/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision eb6d86ee27 (6 days ago), 2022-10-04 22:31:45 -0700
    • Engine revision c08d7d5efc
    • Dart version 2.18.2
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/kimmovirtanen/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] Connected device (3 available)
    • SM G970F (mobile) • RF8M22H9TKT • android-arm64  • Android 12 (API 31)
    • macOS (desktop)   • macos       • darwin-arm64   • macOS 12.6 21G115 darwin-arm
    • Chrome (web)      • chrome      • web-javascript • Google Chrome 106.0.5249.103

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Checklist before submitting a bug

  • I Google'd a solution and I couldn't find it
  • I searched on StackOverflow for a solution and I couldn't find it
  • I read the README.md file of the plugin
  • I'm using the latest version of the plugin
  • All dependencies are up to date with flutter pub upgrade
  • I did a flutter clean
  • I tried running the example project
@zache-fi zache-fi added bug Something isn't working triage labels Oct 11, 2022
@zache-fi zache-fi changed the title [Bug]: [Bug]: Share.shareXFiles doesn't work if XFile is created using File.fromData() Oct 11, 2022
@miquelbeltran
Copy link
Member

miquelbeltran commented Oct 11, 2022

Is it possible to send binary data using a share Intent on Android without "writing the file down" and sharing a URI? Afaik, Android Intents have a hard limit of like 500kb to 1MB (different info sources)

If that's possible, then that would be an option, if not, we would still need to write the file somewhere, an option would be that the shareXFile method writes the file into the app internal storage before sharing, the question is when should this file be deleted.

By making file paths mandatory, we make sure that the developers take care of deleting those temporal files eventually, instead of putting that responsibility to the plugin.

@zache-fi
Copy link
Author

zache-fi commented Oct 15, 2022

I think that idea of using intents for this is doomed to fail as eventually there will be larger files to share that intent allows. However, with Android, you could just save the file to application specific cache directory and let the OS delete it when the disk space is low, the app is closed, etc. I think that it works the same in iOS.

Flutter documentation

Also, the major advantage of removing the path dependency would be one step towards supporting file shares in the web platform, which would go through HTTP POST and doesn't need actual files on disk.

@miquelbeltran miquelbeltran added enhancement New feature or request share_plus Feature, Enhancement, Bug Fixes for Share Plus Plugin android Hacktoberfest Issues taking part in Hacktoberfest and removed bug Something isn't working triage labels Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android enhancement New feature or request Hacktoberfest Issues taking part in Hacktoberfest share_plus Feature, Enhancement, Bug Fixes for Share Plus Plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants