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.

Bad fileName on Android Picked Video [🐛]

See original GitHub issue

Description

When using launchImageLibrary on Android and picking a video, the fileName comes back with the content URI, in the form content://com.android.providers.media.documents/document/video:1752 rather than an actual path/file name. This is of course unusable and throws an error when we try to save the file.

Picking a video on iOS works fine. Taking a new video on both iOS and Android works fine.

I am far from a Java expert, but it looks like the video file is being delivered by the Document Provider, but there doesn’t seem to be a data column when I attempt Cursor cursor = activity.getContentResolver().query(contentURI, null, null, null, null);

How to repeat issue and example

On Android (version 12), launch picker with mediaType mixed or video. Select a video. ImagePickerResponse comes back as:

{
  "assets": [
    {
      "height":1920,
      "width":1080,
      "type":"video/mp4",
      "duration":11,
      "fileName":"video:1744",
      "bitrate":21581279,
      "fileSize":30545603,
      "uri":"content://com.android.providers.media.documents/document/video%3A1744"
    }
]}

Our code calling launchImageLibrary:

launchImageLibrary(
  {
    mediaType: "mixed",
    includeBase64: false,
    selectionLimit: 0,
  },
  onMediaSelected,
)

Solution

Need the real file path for videos.

Additional Information

  • Image Picker version: 4.7.3
  • React Native version: 0.63
  • Platform: Android 12
  • Development Operating System: MacOS
  • Dev tools: Android Studio Arctic Fox | 2020.3.1 Patch 3

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:6

github_iconTop GitHub Comments

2reactions
pierroocommented, Apr 7, 2022

Facing the same issue, did you come up with a solution since @jfries289 ? That would be very helpful 😃

0reactions
simonNeocommented, Nov 24, 2022

@simonNeo questions about this line

const newFileName = getFileName(file); // generate file name by file.type or anything you like

I’m not sure if it’s me being stupid, but I’d like to get an original file name, is there a way to achieve this with react-native-fs?

sorry, I’m not sure how to get original file name. In some case, It seems that selected file with react-native-image-picker is a reference of original file, which has fake file name. so I don’t trust in file.name that react-native-image-picker provided.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to get file name from URI - android - Stack Overflow
Here is the code for getting name of file from url. Uri u = Uri.parse("www.google.com/images/image.jpg"); File f = new File("" + u); f....
Read more >
bboissin@google.com - Monorail
with chrome on android, go to drive.google.com/m/ (mobile interface), ... filename-for-video.mp4 ... Still a bug, but not in chrome.
Read more >
FileProvider - Android Developers
FileProvider is a special subclass of ContentProvider that facilitates secure sharing of files associated with an app by creating a ...
Read more >
Create resizable bitmaps (9-patch files) - Android Developers
Enter a filename for your NinePatch image and click OK. Your image will be created with the .9.png file extension.
Read more >
Known issues with Android Studio and Android Gradle Plugin
If Studio doesn't start after an upgrade, the problem may be due to an invalid Android Studio configuration imported from a previous version...
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