I am not able to getdownloadurl() from firebase. Please anybody help here's my code and error. (I am using Fragment)

Ankit meena

HERE IS MY CODE:

 private void uploadFile() {
    //checking if file is available
    if (filePath != null) {
        //displaying progress dialog while image is uploading
        final ProgressDialog progressDialog = new ProgressDialog(getContext());
        progressDialog.setTitle("Uploading");
        progressDialog.show();

        //getting the storage reference
        StorageReference sRef = storageReference.child(Constants.STORAGE_PATH_UPLOADS + System.currentTimeMillis() + "."
                + getFileExtension(filePath));

        UploadTask uploadTask = storageReference.putFile(filePath);

        Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
            @Override
            public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
                if (!task.isSuccessful()) {
                    throw task.getException();
                }

                // Continue with the task to get the download URL
                return sRef.getDownloadUrl();
            }
        }).addOnCompleteListener(new OnCompleteListener<Uri>() {
            @Override
            public void onComplete(@NonNull Task<Uri> task) {
                if (task.isSuccessful()) {
                    Uri downloadUri = task.getResult();

                    Postmember postmember = new Postmember();
                    DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();

                    postmember.setType("iv");

                    String id = mDatabase.push().getKey();
                    mDatabase.child(id).setValue(postmember);


                } else {
                    // Handle failures
                    // ...
                }
            }
        });
    }

}

HERE IS MY ERROR:

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: Cannot upload to getRoot. You should upload to a storage location such as .getReference('image.png').putFile... java.lang.IllegalArgumentException: Cannot upload to getRoot. You should upload to a storage location such as .getReference('image.png').putFile... at com.google.firebase.storage.UploadTask.run(UploadTask.java:213) at com.google.firebase.storage.StorageTask.lambda$getRunnable$7$StorageTask(StorageTask.java:1072) at com.google.firebase.storage.-$$Lambda$StorageTask$q9YBoR_A8LB-JxTCx8JRQvabaZs.run(Unknown Source:2) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923)

Alex Mamo

The following error:

E/StorageException: Cannot upload to getRoot. You should upload to a storage location such as .getReference('image.png').putFile

Says very clear what the problem is. There is no way you can upload a file directly to the root directory without a name and a file extension. So the line that is causing you trouble is:

UploadTask uploadTask = storageReference.putFile(filePath);

Without seeing how the storageReference object is defined, I can say that most likely it points to the root directory. To solve the problem, you should change the above line of code to:

StorageReference sRef = storageReference.child(Constants.STORAGE_PATH_UPLOADS + System.currentTimeMillis() + "."
            + getFileExtension(filePath));
UploadTask uploadTask = sRef.putFile(filePath);

So the correct object that should be used is sRef, as it points to the right path and not storageReference.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I am not able to get data from my localhost using this code. Please help me. I am getting nil

I am not able to delete items in my todo list made with react, please help me with error in my code

Why i am not able to change the dummy variable here in my code?

I am unable to Decrypt my text but I am able to encrypt can someone please check my code

I'm not able to load my HTML page using ngroute module from angularjs. My code looks fine to me. What mistake am I making?Please review the code

My server was hacked a encoded code was injected. i was not able to know what was the purpose of this code ? Please anybody help me

I am trying to make a table with javascript. It's looking right but don't working. Can anybody help me please?

can anybody help me. I am stuck at this step where Django is not able to show requested page

I am not able to use jAlert in my code ?

I am currently removing jquery from my code and I am not able to convert this Jquery to Javascript

Hi everyone I am a beginner in python and currently I am studying loops. I am not able to answer a question please help me

I am getting error in my Logcat and my app is not running its crashing, Help me please

Hi. Why am I getting "NameError: name 'number' is not defined " for this code? Please help me here as I have no idea

I am just not able to wrap my head around such a simple program.Please help. Below is the program and a representation of my understanding

How can I split string using custom regex? (I am just not able to figure out right regex please help)

Can someone please help me with the code I am writing? (Java)

I am getting an error, while adding DesignGridLayout to my register form. Please help me with this

Using @Qualifier still I am getting UnsatisfiedDependency Exception, can anybody help me with this

i am trying to create foreign keys but i got error 1822 .. please see my code below

I am confused please help me solve it

I am trying to code queue using stack. There is no error while I am running the code but the stack is not able to store the values

I am stuck on making this portion of my code, what do I do from here?

Is this an error in my code, or am I using arrays wrong

here i am getting await can only use inside async function error but i am using async in my function

i am using getElement but it's not working in my code, why?

How am I able to access the Firebase variable AcX in my user?

I am not able to passing the tabnames for tab Fragment

I am unable to run my code by using robotframework due to No keyword with name 'get from dictionary' found error

I am having a problem with a pygame jumping system. Please tell me what's wrong in my code