0

I am trying store a scanned file (using the android document scan library) to FirebaseStorage but i am getting storage exception and i tried all answers online but none works for me.

I am trying store a scanned file (using the android document scan library) to FirebaseStorage but i am getting storage exception and i tried all answers online but none works for me. I can insert data in firebase Realtime database but when it gets to calling the function to upload File then i get the exception below:

The error is below:

E/UploadTask: could not locate file for uploading:content://media/external/images/media/47608
E/StorageException: StorageException has occurred.
    An unknown error occurred, please check the HTTP result code and inner exception for server response.
     Code: -13000 HttpResult: 0
E/StorageException: No entry for content://media/external/images/media/47608
    java.io.FileNotFoundException: No entry for content://media/external/images/media/47608
        at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:149)
        at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:692)
        at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1137)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:958)
        at android.content.ContentResolver.openInputStream(ContentResolver.java:678)
        at com.google.firebase.storage.UploadTask.<init>(com.google.firebase:firebase-storage@@16.0.5:118)
        at com.google.firebase.storage.StorageReference.putFile(com.google.firebase:firebase-storage@@16.0.5:260)
        at io.zentechgh.dms.mobile.app.fragment.AddDocumentFragment.uploadDocumentFile(AddDocumentFragment.java:362)
        at io.zentechgh.dms.mobile.app.fragment.AddDocumentFragment.access$000(AddDocumentFragment.java:60)
        at io.zentechgh.dms.mobile.app.fragment.AddDocumentFragment$2.onComplete(AddDocumentFragment.java:334)
        at com.google.android.gms.tasks.zzj.run(Unknown Source)
        at android.os.Handler.handleCallback(Handler.java:815)
        at android.os.Handler.dispatchMessage(Handler.java:104)
        at android.os.Looper.loop(Looper.java:207)
        at android.app.ActivityThread.main(ActivityThread.java:5763)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
E/StorageException: StorageException has occurred.
    An unknown error occurred, please check the HTTP result code and inner exception for server response.
     Code: -13000 HttpResult: 0

Below is the block of code to upload the document:

// method to upload the document file only
private void uploadDocumentFile(){

    final StorageReference documentFileRef = FirebaseStorage.getInstance()
            .getReference(" Documents /");

    if(documentUri != null){

        documentFileRef.putFile(documentUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

               documentFileRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                    @Override
                    public void onSuccess(Uri uri) {
                        // getting image uri and converting into string
                        Uri downloadUrl = uri;
                        documentUrl = downloadUrl.toString();
                    }
                });


            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                // display an error message
                Toast.makeText(applicationContext, " Failed : " + e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                        double progress = (100.0*taskSnapshot.getBytesTransferred()/taskSnapshot
                                .getTotalByteCount());
                        progressDialog.setMessage("Uploaded "+(int)progress+"%");
                    }
                });;

    }


}

I want to upload the file to storage successfully.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
ali sampson
  • 321
  • 4
  • 7
  • The error indicates that the file pointed to by `documentUri` does not exist. You might want to [check if the file exists](https://stackoverflow.com/questions/16237950/android-check-if-file-exists-without-creating-a-new-one) before trying to upload it. – Frank van Puffelen Dec 24 '18 at 11:35
  • Alright..will check that and get back...Thanks – ali sampson Dec 29 '18 at 17:46
  • Thanks @Frank Van Puffelen .I checked the documentUri using the if statement link this : if(download != null){ //add document} and Its works now – ali sampson Mar 18 '19 at 11:01

0 Answers0