17

I use { Share } from 'react-native'. I shared message successfully, no problem.

Now, I generate dynamically a PDF and save it at local. Is it possible to share the PDF like when I share an url? I didn't find solutions.

After thinking, if PDF isn't possible to share. I have the idea to create dynamically HTML file with react native, then I can share the html file, but it's the same problem. There are no informations about sharing file with { Share}.

I think it's possible with the { Share } from 'react-native' because I saw the same thing on another app on Android.

0

4 Answers 4

13

I had the same problem with the share of react native. I just used this library React Native Share.

And you can pass the url to the file in your file system and it will work properly:

 Share.open({ title: "This is my report ", message: "Message:", url: "file:///storage/emulated/0/demo/test.pdf", subject: "Report", }) 
Sign up to request clarification or add additional context in comments.

9 Comments

Ok! I will try that soon as possible. I will give you some return of result. Thanks you for your help!
@Erased did this work for you on android? It does not work for me.
it always gives an error when trying to send a file, for message it works fine but while sharing file - undefined is not a function(evaluating 'Object.keys(styles{typeof Symbol ==="function: ? Symbol.iterator:"@@iterator"]
perfect, I has been looking for this solution for week
This solution works for ios but not Android. In Android, you have to convert the file to base64 format and then share it. I tried doing it but I am not successful. :(
|
11

This seems to work with the basic Share library from React Native, as long as you have the file:// URL of your PDF file:

Share.share({ url: `file:///path/to/your/file.pdf`, title: 'Download PDF' }) 

I've only tested on iOS, so YMMV.

2 Comments

Can I share a file that is stored in the local folder. Ex: Resources/Images/ex.png ? can that path be specified ?
url is iOS only
1

I had the same issue.

Fixed it by adding file:// in-front of path.

 Share.open({ title: `Share ${fileName}`, url: `file://${filePath}`, type: 'audio/mp3', }) 

1 Comment

Seems to work only on iOS, not in Android.
0

here is my code currently are used in my app for share image link:

shareMessage =async (PhotoLink) => { try { const result = await Share.share({ title:"title goes here", // url:, message: "see the photo"+JSON.stringify(PhotoLink), }); if (result.action === Share.sharedAction) { if (result.activityType) { // shared with activity type of result.activityType } else { // shared } } else if (result.action === Share.dismissedAction) { // dismissed } } catch (error) { alert(error.message); }} ... onPress={() => this.shareMessage(this.props.route.params.url)} 

the share component imported from react native; you can use the like of your PDF to share; my problem is how can I share link with a small image...you know...like telegram ... when you share a photo, like+ massage+photo will share in a frame. I don't know how!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.