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.

[iOS] fileName is not the same as actual file name?

See original GitHub issue

Description

When I pick a photo from the Library, the response.fileName is not the same as the file name in response.uri. When I take a photo, there is no response.fileName at all. I have storageOptions enabled, as well as storageOptions.waitUntilSaved.

I can’t use response.uri to save the photo to local storage, because of this reason: Link

So I use this to return the actual file name:

        let source = response.uri;
        
        if (Platform.OS === 'ios') {
          var subsource = source.substr(source.length - 40)
        }

Then, I use react-native-fs to generate a dynamic uri to the file.

Example response object (this is when I pick from Library)

fileName:"IMG_0637.JPG"
fileSize:3016009
height:1500
isVertical:false
latitude:52.34070833333333
longitude:4.676461666666667
origURL:"assets-library://asset/asset.JPG?id=7DC370EF-5937-4AF6-A6E8-E8016D348568&ext=JPG"
timestamp:"2017-04-23T12:21:45Z"
uri:"file:///var/mobile/Containers/Data/Application/A7F68ABA-DD58-4123-ACFD-AF1596A3EE62/Documents/AD69F6C9-4E1F-45C1-BEC9-06FA1180A29A.jpg"
width:2000

Solution

Something like response.uriFileName that matches the file name in uri would be ideal.

Additional Information

  • React Native version: 0.43.3
  • React Native Image Picker version: 0.26.3
  • Platform: iOS
  • Development Operating System: macOS

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jojomillenniumcommented, Jan 16, 2019

I have the same issue on iOS (Android all good), when taking from Library, with

storageOptions: {
    path: 'myPath',
    waitUntilSaved: true,
    cameraRoll: true,
    skipBackup : true
},

fileName returned is still like : IMG_0002.jpg and the uri has a filename like DFE43C-C0C3-4534-B3E0-C895BA7DD5A1.jpg

  • “react-native”: “0.57.8”,
  • “react-native-fs”: “^2.13.2”,
  • “react-native-image-picker”: “^0.28.0”
1reaction
burenntocommented, Aug 7, 2017

Both storageOptions.cameraRoll AND storageOptions.waitUntilSave need to be true in order for captured media to have fileName and timestamp.

This is mentioned in #394 and I’ve submitted #658 to update the README.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[iOS] fileName is not the same as actual file name? #576
Description When I pick a photo from the Library, the response.fileName is not the same as the file name in response.uri.
Read more >
Original file names of pictures changed b… - Apple Community
Starting to use Photos and iCloud Photo Library more extensively I now noticed that exported originals seem to have altered filesnames.
Read more >
What characters are allowed in a iOS file name?
iOS is UNIX based and as such I suppose it supports almost any characters in filenames. UNIX allows white spaces, <, >, |,...
Read more >
Solved: Saving files from iPhone browser changes name to "...
Clicking this option asks me for the location and the name of the file, but the name used to be inherited from the...
Read more >
Path.GetFileName Method (System.IO) - Microsoft Learn
Returns the file name and extension of a file path that is represented by a ... so the behavior of the GetFileName method...
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