react-native-share: Permission denied for the attachment

Hey and thank you for your amazing work. Basically I am trying to send an attachment through email but I am getting a Permission deined for the attachment error on Android.

On iOS the path just gets written after message body…

The file Im trying to send is a vcf file (VCard), the url Im trying to send looks like this: file:///data/user/0/com.appName/files/Teste-ABC.vc

my shareOptions object:

shareOptions: {
    title: 'Share VCard',
    url: `file://${file}`,
    type: 'vcf',
    message: 'VCard Test'
},

And, Im using the shareSingle option like this:

Share.shareSingle(Object.assign(shareOptions, {
    "social": "email"
}));

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 17 (1 by maintainers)

Most upvoted comments

for anyone trying to share vcard on both platforms. This method works for me. I am using RNFetchBlob and utf8

const vCard = `
BEGIN:VCARD
VERSION:3.0
N:Gump;Forrest;;Mr.;
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;VALUE=URI;TYPE=GIF:http://www.example.com/dir_photos/my_photo.gif
TEL;TYPE=WORK,VOICE:(111) 555-1212
TEL;TYPE=HOME,VOICE:(404) 555-1212
ADR;TYPE=WORK,PREF:;;100 Waters Edge;Baytown;LA;30314;United States of America
LABEL;TYPE=WORK,PREF:100 Waters Edge\nBaytown\, LA 30314\nUnited States of America
ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
LABEL;TYPE=HOME:42 Plantation St.\nBaytown\, LA 30314\nUnited States of America
EMAIL:forrestgump@example.com
REV:2008-04-24T19:52:43Z
END:VCARD
`
const vCardBytes = utf8.encode(vCard);
const vCardBase64 = RNFetchBlob.base64.encode(vCardBytes);
                if (Platform.OS === 'android') {
                    Share.open({
                        url: 'data:text/x-vcard;base64,' + vCardBase64,
                        filename: 'VCard',
                    })
                        .catch(err => { console.log(err) })
                } else {
                    const filepath = RNFetchBlob.fs.dirs.CacheDir + '/vcard.vcf'
                    RNFetchBlob.fs.createFile(filepath, vCardBase64, 'base64').then(async () => {
                        await Share.open({
                            //url: 'data:text/vcard;base64,' + RNFetchBlob.base64.encode(data),
                            url: 'file://' + filepath,
                            //type: 'text/x-vcard',
                            filename: 'VCard',
                        })
                    })
                        .catch(err => {
                            console.log(err)
                        })
                        .finally(() => {
                            RNFetchBlob.fs.unlink(filepath)
                        })
                }

permission denied for attachment react native

@avencat Removing type from options is working as intended 👍

@RUIFERNANDE5 Ok thank you, but I tried text/xcard and my test Android phone won’t show the sms/mms option so, according to this page, I put text/x-vcalendar and it works for my case so I think I’ll let as it… 😉

Thank you for sharing with me on that issue, have a good day! 😄

@RUIFERNANDE5 I was able to solve the problem by using rnfs.ExternalStorageDirectoryPath thank you for the solution! 😃 I also wondered if you know how to share a vcf via MMS? (When I click on message, I get an error saying that files must be shared via MMS and not SMS… (On Android)

Thank you for your time! 😃

I was able to solve this on android by saving the file on ExternalStorageDirectoryPath. Im not using react-native-share on iOS anymore, although If im correct it worked when I first created a Dir and then generated the file inside that Dir.