Skip to content

Cannot Share a File with Share Sheet #16743

Closed

Description

@rodydavis

Steps to Reproduce

https://pub.dartlang.org/packages/share does not allow you to share a file. Only String. I am trying to Share a .vcf file for example.

Future<String> get _localPath async {
   final directory = await getApplicationDocumentsDirectory();

   return directory.path;
 }

 Future<File> get _localFile async {
   final path = await _localPath;
   return new File('$path/contact.vcf');
 }

 Future<String> readCounter() async {
   try {
     final file = await _localFile;

     // Read the file
     String contents = await file.readAsString();

     return contents;
   } catch (e) {
     // If we encounter an error, return 0
     return "";
   }
 }

 Future<File> writeCounter(String data) async {
   final file = await _localFile;

   // Write the file
   return file.writeAsString('$data');
 }

 void shareContact() async {
   String str = "BEGIN:VCARD\n" +
       "VERSION:4.0\n" +
       "N:Gump;Forrest;;;\n" +
       "FN:Forrest Gump\n" +
       "ORG:Bubba Gump Shrimp Co.\n" +
       "TITLE:Shrimp Man\n" +
       "TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212\n" +
       "TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212\n" +
       "EMAIL:[email protected]\n" +
       "REV:20080424T195243Z\n" +
       "END:VCARD";

   writeCounter(str);
   final file = await _localFile;

   share(file.toString());
 }

Activity

  1. dmjones commented on Apr 23, 2018

    @dmjones

    I'd also like to send an image. Not sure if it would solved by the fix for this issue, so happy to open a separate issue if needed. Related SO question: https://stackoverflow.com/q/44181343/474189.

  2. perlatus commented on May 11, 2018

    @perlatus
    Contributor

    For a .vcf file, if you wouldn't want it in a public directory like Download you could probably write it to /sdcard/Android/Data/your.rev.domain.name and pass the path to the shareFile method mentioned above with text/vcard as the mimeType.

  3. hillelcoren commented on Jun 20, 2018

    @hillelcoren
    Member

    It'd be great if there was an easy way to share a PDF file.

    I found this comment but would obviously prefer not to have to modify the code.

  4. zoechi commented on Dec 4, 2018

    @zoechi
    Contributor

    Merging with #19607

  5. Allan-Nava commented on Mar 6, 2019

    @Allan-Nava

    How can I upload a file to server?

  6. kamleshwebtech commented on Feb 15, 2021

    @kamleshwebtech

    How can we share an assets images by using Share package? any solution, please share. Thanks.

  7. github-actions commented on Aug 5, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  8. locked as resolved and limited conversation to collaborators on Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions