android – Firebase Storage :UploadTask: could not locate file for uploading-ThrowExceptions

Exception or error:

I have custom gallery for uploading files to firebase storage it works well most of the time but when i tried to upload this particular PDF file from phone storage i start getting exception

E/StorageException: /storage/emulated/0/WhatsApp/Media/WhatsApp Documents/Scan Feb 5, 2020.pdf: open failed: ENOENT (No such file or directory)
W/UploadTask: could not retrieve file size for upload file:///storage/emulated/0/WhatsApp/Media/WhatsApp%20Documents/Scan%20Feb%205%2C%202020.pdf

I can send same file to whatsapp and other platforms without any issues.Before creating URI for uploading a file i generate logcat for file path to be upload.File path needs to upload

/storage/emulated/0/WhatsApp/Media/WhatsApp Documents/Scan Feb 5, 2020.pdf

Can anyone tell me why i am getting this exception. if it’s due to "," after 5 in file name then i won’t be able to give user exact same name of file when he receive. Any help please.

Uri fileUri = Uri.fromFile(new File("/storage/emulated/0/WhatsApp/Media/WhatsApp Documents/Scan Feb 5, 2020.pdf"));

StorageReference mStorageReference = FirebaseStorage.getInstance().getReference();
            final StorageReference storageReference;

            storageReference =  mStorageReference.child("Documents").child(fileUri.getLastPathSegment());
            String finalAttachmentType = attachmentType;
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *