Firebase exception:Object Does Not Exist

Viewed 2967

I was uploading a image to Firebase Storage and this error keeps coming

E/StorageException: StorageException has occurred. Object does not exist at location. Code: -13010 HttpResult: 404 E/StorageException: { "error": { "code": 404, "message": "Not Found. Could not get object",
"status": "GET_OBJECT" }} java.io.IOException: { "error": { "code": 404, "message": "Not Found. Could not get object", "status": "GET_OBJECT" }}

This is my code:

StorageReference postimage_path=firebaseStorage.child("Post Image").child(random+".jpg");

postimage_path.putFile(newposturi);
postimage_path.getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() {
    @Override
    public void onComplete(@NonNull Task<Uri> task) {
        if(task.isSuccessful())
        {

            Uri download_url=task.getResult();
            Map<String,String> postmap=new HashMap<>();
            postmap.put("download url",download_url.toString());
            postmap.put("Description",post);
            postmap.put("user_id",currentuser);
            postmap.put("timestamp",""+FieldValue.serverTimestamp());
            postfirestore.collection("Posts").add(postmap).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
                @Override
                public void onComplete(@NonNull Task<DocumentReference> task) {
                    if(task.isSuccessful()){
                        Toast.makeText(PostActivity.this, "Post Successful", Toast.LENGTH_SHORT).show();
                        Intent intent=new Intent(PostActivity.this,MainActivity.class);
                        startActivity(intent);
                        finish();
                    }

                    else{
                    String error=task.getException().getMessage();
                    Toast.makeText(PostActivity.this, "Error while Posting :"+error, Toast.LENGTH_SHORT).show();}
                    newpostprogress.setVisibility(View.INVISIBLE);
                }
            });
        }

2 Answers

The error message is telling you that there's no object in storage with the path you're building like this:

StorageReference postimage_path=firebaseStorage.child("Post Image").child(random+".jpg");

The missing object is causing getDownloadUrl() to fail.

You'll have to do some debugging to figure out what the path should be, and make sure the named object actually exists.

Check your firebase permissions on storage. It should have read/write permission. Also check the firebase rules.

Other important thing is,

Runtime permissions added in marshmallow. Enable storage permissions on android device. android marshmallow+ you have to allow the permissions for app.

Related