document-picker
document-picker copied to clipboard
File name is missing for some files in picked response
Bug report
Summary
Picked response is not same for all files. For some files "fileName", "fileSize", "name" are missing.
Reproducible sample code
I cannot provide any Reproducible sample code since same code is used for all files no matter whether the response contains "fileName", "fileSize", "name" or not.
Steps to reproduce
1.Please run below code let res = await DocumentPicker.pick({ type: [DocumentPicker.types.allFiles], });
- Then try to attach these files 5_60551058566666003.pdf
Picker response would be like this
fileName: "5_60551058566666003.pdf"
fileSize: 233370
name: "5_60551058566666003.pdf"
size: 233370
type: "application/pdf"
uri: "content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2F5_60551058566666003.pdf"
then try to upload this file Robin.pdf
Picker response would be like this size: 99763 type: "application/pdf" uri: "content://media/external/file/245998"
Both are PDF's only. But their response is different.
Environment info
react: 16.11.0 => 16.11.0
react-native: 0.62.2 => 0.62.2
react-native-document-picker: "3.5.4",
Android version: 9
Since there is no file name in the response, unable to proceed for further.
hello and thanks for reporting, and for including files which could be used to reproduce the issue (!) 👍 .
I tried this on my physical device (honor 20 pro, android 10). Also tried on pixel 2 android emulator with android 9.
It works for me when I pick the robin.pdf file from downloads folder, even though the output is a little different from yours:
{
"fileCopyUri": "content://com.android.providers.downloads.documents/document/msf%3A31728",
"size": 99763,
"name": "Robin.pdf",
"type": "application/pdf",
"uri": "content://com.android.providers.downloads.documents/document/msf%3A31728"
}
So I'm afraid that unless you provide some more information, like what emulator you used and if you picked from downloads folder or somewhere else, this is not actionable.
Thank you! :)
@vonovak Thank you for your response.
I tired in Honor 9N and iPhone 11 devices. I tired from Downloads folder and Phone Storage Root Folder.
@Yandamuri and in both cases you did not receive file's name and size? This is weird 🤔
Are you sure you're not adding some custom logic that modifies the response from picker? Please provide a runnable repro: https://stackoverflow.com/help/minimal-reproducible-example
thank you! :)
@vonovak
This is the small snippet I am calling
let result = await DocumentPicker.pick({
type: [DocumentPicker.types.allFiles]
});
This is what observed today in my mobile Honor 9N
I have downloaded this image from google and it directly downloaded to Downloads folder.
This is the image - road-g29d987485_1920.jpg

Following is the response when try to pick this image
If we observe the above response, we can notice that fileName in fileCopyUri and actual FileName are totally different due to which file picking is eventually getting failed as fileUploader is unable to find the file due to wrong fileName
Then I renamed the above file as renamed.js and tried to pic. Then below is the response
This time response contains right filename in fileCopyUri which is why file was able to be uploaded by fileUploader.
So, here observation is when any file is directly downloaded form internet and try upload then it fails. If I rename and try then it will be successfully picked.
hello, as you can see here
https://github.com/rnmods/react-native-document-picker/blob/104b9a99cdbeef50d1aca136989458ed0a66f938/src/index.tsx#L6
the picker returns name and size, not fileName and fileSize, so the logs you're showing are not logs directly from the picker so that's what I found a little confusing.
What you outlined in the last post seems to be a different problem from the one you asked originally though.
as for the uri object, it comes from android's content provider and it does not necessarily need to point to a physical location on the device so depending on how the uploader is done, it may not work.
You can use copyTo option to get the file downloaded to device. Without it, fileCopyUri and uri are the same, which is a little confusing.
So, here observation is when any file is directly downloaded form internet and try upload then it fails.
depends on how the uploader is done :)
@vonovak
the picker returns name and size, not fileName and fileSize, so the logs you're showing are not logs directly from the picker so that's what I found a little confusing.
The response is different in different versions of RN
picked response in RN 0.66
picked response in RN 0.63
What you outlined in the last post seems to be a different problem from the one you asked originally though.
I found total two issues
- For some PDF files there is no
nameproperty in picked response. When I rename the PDF then it gives proper response. This solution is also works for some files only. -- This is where I am literally confused and unable to find the reason.
2.When I pic image files from Downloads folder then it's not upload able unless it is renamed. But if I pic image file form any location other than downloads then it's upload able -- Again here I don't really understand the logic.
This library is working fine in iOS.
I literally fed off with this issue. Hence, If you can suggest something about this It would be really great. Otherwise we can close this issue.
Thank you.
Hello, I can assure you 100% that the response of the file picker is the same regardless of the react native version. 100%(!!)
I see the difference between the screenshots, but the difference is not cause by the doc picker library but some other code that you have not provided.
I can take a look at your project and try to figure out the problem, as a paid service if you're interested. If you belive the problem is in the document picker library, then I ask you to provide a runnable reproduction: https://stackoverflow.com/help/minimal-reproducible-example
Thank you and have a nice weekend 😉
@vonovak
I can assure you 100% that the response of the file picker is the same regardless of the react native version. 100%(!!)
Then there is no issue with it.
But Please check the two issues which I outlined earlier
-
For some
.pfdfilesnameis not included in picked response. -
For some
.pdffiles and.jpegfiles,uriin the picked response is not able to be identified byRNFetchBlob.fs.statwhich results in unidentified location of the file. Eventually failing to upload.
You can find the Reproducible Demo here
Please find the below pdf file for which I am not getting name in picked response
263325.pdf
Please find the below .jpeg file for which uri path is not able to be identified by RNFetchBlob.(You can find why I am using RNFetchBlob in the code in the attached repository.)

Please note I tried to pic the above file form Downloads directory.
Please find the below .jpeg file for which uri path is able to be identified by RNFetchBlob.(You can find why I am using RNFetchBlob in the code in the attached repository.)

Please note I tried to pic the above file form DCIM directory(Taken by camera).
I am using Honor 9N.
@vonovak Can you please give any update on my above comment.
Still I am facing this issue.
hello, I am sorry, I'm lacking free time to properly investigate. For now I'd recommend trying to use the copyTo option.
I am also facing the same issue. Not getting a name for some files which is inside Internal Storage.
This is the response after pickMultiple
const response = await DocumentPicker.pickMultiple({ type: DocumentPicker.types.pdf, });
[{"fileCopyUri":null,"size":222894,"type":"application/pdf","uri":"content://media/external/file/255527"}]
Device - Android Honor 9N. I have a memory card in my phone and internal storage.
By default, the picker opens the Recents folder, if I pick from Recents then it works file.
[{"fileCopyUri":null,"size":825854,"name":"1_updated_Coverage - Group Mediclaim Insurance.pdf","type":"application/pdf","uri":"content://com.google.android.apps.docs.storage/document/acc%3D7%3Bdoc%3Dencoded%3DtgAOl7e%2F8kUqvSWSFomAmrv1JnxxhdGaGAXj2JF8gkFI%2FgufeM%2Fcdv8%3D"}]
same problem here, only android not return name or filename, ios work normally
Hello, I tried to reproduce the issue on my Honor 20 Pro but could not reproduce.
I fixed the typings to signal that the name returned can be null as can be seen here
I'm afraid there might be cases where looking some of the metadata does not work and the response will include null.
Please open a new issue with reproduction steps if the problem persists, thank you.