question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shares the last photo in the library instead of the provided file.

See original GitHub issue

Steps to reproduce

  1. Build for IOS device.
  2. Before opening the app, make a photo/screenshot
  3. Share.shareSingle. for Instagram
  4. Magic happens here. Instead of the URL I am trying to share, it takes the first photo in the library I made in step 2.

Expected behaviour

It should load (share) the image I am giving in the URL param

const url = 'https://d29fp8qybdwwik.cloudfront.net/xgowQvXyP624QXwhQ/mBRfn2fcwD-franciele-cunha-596987-unsplash.jpg'
 RNFetchBlob.config({
      fileCache: true,
      appendExt: "jpeg"
    })
      .fetch("GET", url, {})
      .then(response => {
        let shareOptions = {
          url: "file://" + response.path(),
          type: "image/jpeg",
          social: Share.Social.INSTAGRAM
        };

        Share.shareSingle(shareOptions)
          .then(res => {
            //Remove files from cache
            response.flush();
          })
          .catch(err => {
          });
      });
url is - file:///var/mobile/Containers/Data/Application/C25DE66E-A60E-4503-B2A9-2A5659D9692E/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_by9mv9rtja9sxvip0z3wup.jpeg

Actual behavior

It shares the last made photo (device) and not the image I am passing to the URL param

PS: It worked fine untill I made a screenshot 😭.

Environment

  • React Native version: ^0.56.0
  • React Native platform + platform version: Iphone 7, IOS 11.4.1

react-native-share

Version: 1.1.1

Update.

While using Share.open and selecting Instagram will work. With Share.singleShare still gets the last photo.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:25 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
nicubarbaroscommented, Sep 5, 2018

Hey. I finally made it work, by saving the media to Camera Roll and then taking the absolute path from there. In case anyone wants to know my solution please check this code. Works both for image and video. Tested only for IOS, I think the android needs to append file:// before the uri.

 shareToInstagram = async (
    mediaUrl = "",
    appendExt = "igo",
    type = "image/jpeg"
  ) => {
    try {
      const tempBlob = await RNFetchBlob.config({
        fileCache: true,
        appendExt
      }).fetch("GET", mediaUrl, {});

      const savedToCameraRoll = await CameraRoll.saveToCameraRoll(
        tempBlob.path()
      );

      const last = await CameraRoll.getPhotos({
        first: 1,
        assetType: "All"
      });
      let shareOptions = {
        url: last.edges[0].node.image.uri,
        type,
        social: Share.Social.INSTAGRAM
      };

      const response = await Share.shareSingle(shareOptions);

      tempBlob.flush();
    
    } catch (error) {

      console.log(error);
    }
  };

3reactions
trackwell-mikecommented, Jan 2, 2021

We’re having this issue as well, and I’d like to clarify that this only happens when sharing to Instagram Feed (enum: INSTAGRAM), not Instagram Stories (enum: INSTAGRAM_STORIES).

@MateusAndrade Does this work for you, sharing to Instagram Feed in iOS?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shares the last photo in the library instead of the provided file.
Build for IOS device. ... Magic happens here. Instead of the URL I am trying to share, it takes the first photo in...
Read more >
View photos and videos shared with you on iPhone
View photos and videos shared with you on iPhone · Tap a photo to view it in full screen, save it to your...
Read more >
Share photos & videos - Android - Google For Families Help
You can share photos, videos, albums, and movies with any of your contacts, even if they don't use the Google Photos app.
Read more >
Google Photos - Apps on Google Play
Google Photos is the home for all your photos and videos, automatically organized and easy to share. - “The best photo product on...
Read more >
How do I share a photo or video in GroupMe?
You can share photos and videos to your GroupMe chats then view and save them as you want. ... From the Photo library,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found