matautd
matautd

Reputation: 19

How do i share a video from react native to Instagram?

I'd like to share a video from my react native app to Instagram. I edit this video file so i'm not getting it directly from my camera roll, but i have a link to it locally which i've logged on my physical iPhone device below:

uri:

"private/var/mobile/Containers/Data/Application/(Long filename).mp4"

and i remove the "/private". What i'm trying to to with this is use 'Linking' from React Native :

shareToApp = (uri) => {
        amendedURI = 'file://' + uri;       
        let encodedURL = encodeURIComponent(amendedURI);  
        let instagramURL = 'instagram://library?AssetPath=${' + encodedURL + '}';
        return Linking.openURL(instagramURL);
}

but the screen where you share to 'Feed' or 'Stories' displays the last item in my gallery (pic or video), not the video i've passed as the 'uri'

Is there something here which prevents me from achieving this?

Upvotes: 0

Views: 2712

Answers (1)

Rajan
Rajan

Reputation: 1568

You can use react-native-share provided by react-native-community.

let shareOptions = {
    url: `file://${this.state.files[0].data}`, //FetchBlob file path
    type: `video/${file.extension}`, //file.extension contains the extension of the file
    social: Share.Social.INSTAGRAM
};
await Share.shareSingle(shareOptions);

Upvotes: 1

Related Questions