react-native-share: Can't upload image on Instagram Feed

Hi,

Can’t upload image on Instagram Feed, I tried with Instagram Story and Direct and it worked successfully, but Instagram Feed no.

I receive the following message: the image cannot be uploaded.

React native versión: 0.59.9 React native share: 1.2.1

I try with base64:

    const configOptions = { 
      fileCache: true,
      path: fs.dirs.DownloadDir + `/$${file.name}`
    };

    config(configOptions).fetch('GET', image).then(resp => {
      filePath = resp.path();
      return resp.readFile('base64');
    }).then(async base64Data => {
      base64Data = `data:image/${file.extension};base64,` + base64Data;

      await Share.shareSingle({
        url: base64Data,
        social: Share.Social.INSTAGRAM,
        filename: `/${file.name}`
      });
    })

And try with file:

   const configOptions = { 
      fileCache: true,
      path: fs.dirs.DownloadDir + `/$${file.name}`
    };

    config(configOptions).fetch('GET', image).then(resp => {
      filePath = resp.path();
      return resp.readFile('base64');
    }).then(async base64Data => {
      // base64Data = `data:image/${file.extension};base64,` + base64Data;

      await Share.shareSingle({
        url: `file://` + filePath,
        social: Share.Social.INSTAGRAM,
      });
    })

Please, I need help, very thanks.

I try adding type or filename and nothing.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 21

Most upvoted comments

I’m having the same issue as well, the follow opens up Instagram and shares my latest photo in my Photo Library, and NOT the url that I passed in.

const shareOptions: ShareSingleOptions = {
        title,
        url: imageUri,
        social: Share.Social.INSTAGRAM,
      };
Share.shareSingle(shareOptions);

This is an Instagram error with their last update. Android thread here with more info.

Temporary workaround: join Beta program and install latest Beta update, it should work!

Update, it works now with 136.0.0.34.124 version

@MateusAndrade I had a few hours this afternoon so I gave it a shot, however I could not get my Android Studio to run in debugger mode. Therefore had a hard time figuring out what was happening in the Native Java code.

I’m going to stop and let you take over. I hope this helps you to proceed with your debugging.

I will share the code snippets which will make it possible for you to see the IG Feeds option to appear.

The below snippets of code are added to example/App.js

The Code

  1. I added a new button Share via IG Share Sheet
        <View style={styles.button}>
          <Button onPress={shareToInstagramViaShareSheet} title="Share via IG Share Sheet" />
        </View>
  1. I created a new function shareToInstagramViaShareSheet with the options.
  /**
   * This will display the Instagram Sharesheet from which you
   * can select one of the following three options
   *
   * 1. Direct: This will let you send image direct message to an individual contact on IG
   * 2. Feed: Open up the Instagram Feed with the image
   * 3. Stories: Open up the Instagram Story with the image.
   */
  const shareToInstagramViaShareSheet = async () => {
    const shareOptions = {
      title: 'Share image to one of these Instagram options.',
      social: Share.Social.INSTAGRAM,
      url: images.image1,
    };

    try {
      const ShareResponse = await Share.shareSingle(shareOptions);
      setResult(JSON.stringify(ShareResponse, null, 2));
    } catch (error) {
      console.log('Error =>', error);
      setResult('error: '.concat(getErrorString(error)));
    }
  };
  1. Now when you run the example and tap on the button you should see the Feeds option.

Screenshots Screenshot_20200405-160316

Screenshot_20200405-160423

@MateusAndrade Sorry, that was my note from my previous comment. It does not work for Instagram Stories as well when using a file path. It only works fine when using the base64 string.

Note: When using above code to share a file directly to Instagram Stories, nothing happens. It does NOT open instagram. It silently Fails. I do not see any error message as well. I did not investigate this further. It is possible this is user error on my end. But just wanted to let you know about this.

Sharing a file using the path to Instagram Stories fails and it does not work.