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 share PDF file with WhatsApp or email (Android) #592

Closed
prasad456 opened this issue Sep 25, 2019 · 8 comments
Closed

Can't share PDF file with WhatsApp or email (Android) #592

prasad456 opened this issue Sep 25, 2019 · 8 comments
Labels
bug os: android stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@prasad456
Copy link

Steps to reproduce

  1. Implemented as instructed for PDF Share
  2. Added FileProvider(Local) in Manifest
  3. Added Two different method to share on Android & iOS

Expected behaviour

Tell us what should happen
Must share options for pdf share

Actual behaviour

Tell us what happens instead
Nothing

Environment

  • React Native version:
  • React Native platform + platform version: iOS 9.0, Android 5.0, etc
    "react": "16.8.6",
    "react-native": "0.60.0",

react-native-share

Version: npm version or "master"
"react-native-share": "^2.0.0",

Link to repo (highly encouraged)

https://github.com/

@prasad456 prasad456 added the bug label Sep 25, 2019
@jgcmarins
Copy link
Member

do you have any reproducible repo?

@prasad456
Copy link
Author

@jgcmarins
I just implemented the instructions as mentioned here for sharingpdf
https://github.com/react-native-community/react-native-share

But while adding File provider in manifest, having merge issues the android defailt file providing already iusing other package called react-native-image-crop-picker. So I created a File provider same as Android ones.
Build errors are fixes but can't share the pdf

The below line is not working while i had logs within the method
await Share.open({ url: base64Data });

@MateusAndrade
Copy link
Collaborator

Hi @prasad456 , you can provide a sample code showing how you are calling rn-share? Also, have you tried sharing the PDF relative path?

@prasad456
Copy link
Author

This is code trying for share
My reference of the bloew code is https://github.com/react-native-community/react-native-share#troubleshooting

`

sharePDF = (item) => {
    const url = item.docLink
    if (Platform.OS == 'ios') {
        this.sharePDFWithIOS(url, 'application/pdf')
    }
    else {
        console.log('PDF share with android', item)
        this.sharePDFWithAndroid(url, 'application/pdf')
    }
}

sharePDFWithAndroid(fileUrl) {
    let filePath = null;
    let file_url_length = fileUrl.length;
    const configOptions = { fileCache: true };
    console.log('PDF android share', filePath)
    RNFetchBlob.config(configOptions)
        .fetch('GET', fileUrl)
        .then(resp => {
            filePath = resp.path();
            console.log('PDF RNF then1', filePath)
            return resp.readFile('base64');
        })
        .then(async base64Data => {
            base64Data = await `data:application/pdf;base64,` + base64Data;
            console.log('PDF RNF then2', base64Data)

            try {
                await Share.open({ url: base64Data });
                // remove the image or pdf from device's storage
                await RNFS.unlink(filePath);
            } catch (error) {
                console.log('PDF then2 err', error)
            }
        });
}

sharePDFWithIOS(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);
        });
}`

@tuncaulubilge
Copy link

@prasad456
For me, RNFS.unlink was causing the issue, so try to remove it and see if that fixes the issue for you. Whatsapp or gmail might still be uploading the image so we shouldn't remove that file right away.

@jgcmarins
Copy link
Member

jgcmarins commented Nov 12, 2019

@efecantekin check if it's related to #628

@stale
Copy link

stale bot commented Jan 11, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and i will leave this open.

@stale stale bot added the stale There has been a lack of activity on this issue and it may be closed soon. label Jan 11, 2020
@stale
Copy link

stale bot commented Jan 18, 2020

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.

@stale stale bot closed this as completed Jan 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug os: android stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

5 participants