Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share images and files on react-native using Expo

I've saved the file i want to share locally using FileSystem.downloadAsync

Share.share works fine for iOS. How can I share an image I have saved locally on Android?

I've tried

  • https://github.com/lucasferreira/react-native-send-intent
  • https://github.com/react-native-community/react-native-share

Both these solutions do not seem to work with Expo.

I'm using react-native version : https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz

FileSystem.downloadAsync(url, FileSystem.documentDirectory+filename).then(({uri})=>{

    if(Platform.OS == "android"){
        // ???
    }
    else{
        Share.share({url:uri});
    }

})

Is there something i'm missing?

like image 709
Madhavan Malolan Avatar asked Nov 22 '18 04:11

Madhavan Malolan


1 Answers

Since SDK33, you can use Expo Sharing to share any type of file to other apps that can handle its file type even if you're on Android.

See : https://docs.expo.io/versions/latest/sdk/sharing/

Usage is pretty simple :

import * as Sharing from 'expo-sharing'; // Import the library

Sharing.shareAsync(url) // And share your file !
like image 189
Yassine El Bouchaibi Avatar answered Sep 27 '22 19:09

Yassine El Bouchaibi