shareAsync: Not allowed to read file under given URL.

Trying to share a camera image using Sharing.shareAsync. Believe I have a proper URI but it’s throwing the error Not allowed to read file under given URL.

URI is file://storage/emulated/0/DCIM/934a455e-832d-4591-98b7-5c4bd821edfa.jpg

App has CAMERA & CAMERA_ROLL permissions and my app.json includes the following:

"android": {
      "permissions": [
        "CAMERA",
        "READ_EXTERNAL_STORAGE",
        "WRITE_EXTERNAL_STORAGE"
      ]
    }

TIA.

Seems to be a bug in Sharing. Copied to local storage and was able to get it to work.

adding more context here for people that stumble on it - this is the stackoverflow answer for the same question: https://stackoverflow.com/a/61241254/659988


It looks like this may be a bug in the `Sharing` API. You can work around it for now by copying the file to your document directory and then sharing from there. Here's an example: https://snack.expo.io/@notbrent/share-media-library-photo

Relevant code from that example below:

// Placeholder for getting asset from MediaLibrary
let results = await MediaLibrary.getAssetsAsync({ first: 1 });
let asset = results.assets[0];

// Use FileSystem to copy the image from its original location to the app document directory
let assetUriParts = asset.uri.split("/");
let assetName = assetUriParts[assetUriParts.length - 1];
let uri = `${FileSystem.documentDirectory}/${assetName}`;
await FileSystem.copyAsync({
  from: asset.uri,
  to: uri,
});

// Share the image from the uri that you copied it to
Sharing.shareAsync(uri);

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.