react-native-image-picker: Video URI on Android incorrect [🐛]

Description

When picking a video file from an Android device, the URI returned doesn’t work, when I visit the returned URI in Chrome, it says file does not exist. Works fine on iOS

Sample response from the launchImageLibrary: {"fileName": "90510942_824331778088534_328930688839450624_n.mp4", "fileSize": 320924, "uri": "content://com.google.android.apps.photos.contentprovider/-1/2/content%3A%2F%2Fmedia%2Fexternal%2Fvideo%2Fmedia%2F48/ORIGINAL/NONE/2051731147"}

How to repeat issue and example

  • step to reproduce the issue

Solution

What needs to be done to address this issue?

Additional Information

  • Image Picker version: ^3.1.1
  • React Native version: ^0.61.5
  • Platform: Android
  • Development Operating System: macOS
  • Dev tools: Android Studio

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 18
  • Comments: 29 (2 by maintainers)

Most upvoted comments

Any solution for this ?

Any solution for this ?

I applied a temporary solution;

yarn add react-native-fs

import RNFS from 'react-native-fs';

async videoUrlCopy(uri, fileName) {
        const destPath = `${RNFS.TemporaryDirectoryPath}/${fileName}`;
        await RNFS.copyFile(uri, destPath);
        await RNFS.stat(destPath);
        return destPath;
    }

Any solution on how to upload the video using the content uri?

this is a very serious problem and a solution is needed.

@sekizlipenguen @Janak-Nirmal @arhmnsh What do you want to do with the video file?

  • Play it in your app? (Content URI will do for that)
  • Upload to ur backend? (Content URI will do for that)
  • Share it with other apps? (I don’t know how share works)

@arhmnsh why do u enter the URI in chrome, thats not how it works.

Tell your use cases.

I don’t think Content URI is enough to upload to our backend. When trying to upload the file to firebase storage, I get a Permission Denial error when using the Content URI.

Permission Denial: reading com.google.android.apps.photos.contentprovider.impl.MediaContentProvider uri content://com.google.android.apps.photos.contentprovider/-1/2/content:/media/external/video/media/36/ORIGINAL/NONE/video/mp4/1860530892 from pid=7391, uid=10154 requires the provider be exported, or grantUriPermission()

@ramos07 solution works for me but with a slightly change:

const { originalFilepath } = await stat(videoUri);
    const uri = `file://${originalFilepath}`
    return uri;

Any solution for this ?

+1