question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iOS => Sharing PDF with GMail or WhatsApp does not work...

See original GitHub issue

Hey there,

i am trying to share a pdf as base64 with Gmail and WhatsApp. Sharing with the “normal” iOS Mail App works just fine, but sharing with WhatsApp & Gmail fails. On Gmail the shared pdf is some kind of weird data with this structure => 123456.dat When sharing to WhatsApp i have several problems.

  1. When title & message of share options is empty i get an error something like: “This object cannot be sent. Please choose another object.”
  2. If i add title & message i can only share the title & message text without the pdf file

Here is my code:

RNFetchBlob.config({ fileCache: true })
    .fetch("GET", fileUrl)
    // the image or pdf is now dowloaded to device's storage
    .then(resp => {
        filePath = resp.path();
        return resp.readFile("base64");
    })
    .then(async base64Data => {
        // here's base64 encoded image or pdf
        // type = application/pdf or image/png
        base64Data = `data:${type};base64,` + base64Data;

        let options = {
            type: type,
            message: "",
            title: "",
            // url: type === MIME_TYPE_PDF ? filePath : base64Data
            url: base64Data
        };

        await Share.open(options);

        // remove the image or pdf from device's storage
        fs.unlink(filePath);
    });

I also tried to share the temp file path instead of the base64 but unfortunatley the file path which is downloaded didn’t have the pdf ending 😄 Anyways… it has to work somehow as it works with the iOS Mail App…

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jgcmarinscommented, Jun 25, 2018

Great! @BigPun86 could you send a PR updating README? Thanks.

1reaction
BigPun86commented, Jun 24, 2018

This issue might be more related to the fetch-blob. Never mind, this is how i fixed it. I actually extended the config options for the RNFetchBlob.config and added a clear path with filename to it. For Android i just left the old code sharing via base64. Now WhatsApp sharing works perfectly and sharing with Gmail has a extension. I set the pdf extension when filetype is application/pdf else i simply use .png which works for any kind of images shared.

static shareWithIOS(fileUrl, type) {
  let filePath = null;
  let file_url_length = fileUrl.length;
  const configOptions = {
    fileCache: true,
    path:
      DIRS.DocumentDir + (type === 'application/pdf' ? '/SomeFileName.pdf' : '/SomeFileName.png') // no difference when using jpeg / jpg / png /
  };
  RNFetchBlob.config(configOptions)
    .fetch('GET', fileUrl)
    .then(async resp => {
      filePath = resp.path();
      let options = {
        type: type,
        url: filePath // (Platform.OS === 'android' ? 'file://' + filePath)
      };
      await Share.open(options);
      // remove the image or pdf from device's storage
      await RNFS.unlink(filePath);
    });
}
static shareWithAndroid(fileUrl, type) {
  let filePath = null;
  let file_url_length = fileUrl.length;
  const configOptions = { fileCache: true };
  RNFetchBlob.config(configOptions)
    .fetch('GET', fileUrl)
    .then(resp => {
      filePath = resp.path();
      return resp.readFile('base64');
    })
    .then(async base64Data => {
      base64Data = `data:${type};base64,` + base64Data;
      await Share.open({ url: base64Data });
      // remove the image or pdf from device's storage
      await RNFS.unlink(filePath);
    });
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

iOS => Sharing PDF with GMail or WhatsApp does not work...
Hey there, i am trying to share a pdf as base64 with Gmail and WhatsApp. Sharing with the "normal" iOS Mail App works...
Read more >
Sending PDF file from gmail to WhatsApp - Apple Community
I do not find any issue in sharing a pdf file from an email ... It happens only when trying to send a...
Read more >
Top 8 Ways to Fix WhatsApp Not Downloading PDFs on ...
Top 8 Ways to Fix WhatsApp Not Downloading PDFs on iPhone and Android · Open the Settings app on the iPhone. · Scroll...
Read more >
FIXED Cannot Send PDF Files, Documents On WhatsApp In ...
Cannot Send PDF Files, Documents On WhatsApp In iPhone. No Send Button In WhatsApp After Update. How to fix cannot send pdf file...
Read more >
Can't share PDF file with WhatsApp or email (Only IOS)
I had similar problem in react native share. Then i use react-native-share for sharing my pdf file. Share.open({ title: "Pdf file", ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found