0

I am trying to make my own chatting application and the problem that I am having is that, when I am trying to upload an image, specifically the profile image of the user then the build Gradle just compiles fine but after installing the app on my phone and when I try to upload an image then There is an error in the logcat.

The Source code is given below.

import java.util.HashMap;
import de.hdodenhof.circleimageview.CircleImageView;

public class SettingsActivity extends AppCompatActivity
{
    private CircleImageView userProfileImage;
    private FirebaseAuth mAuth;
    private DatabaseReference RootRef;
    private static final int GalleryPick = 1;
    private StorageReference UserProfileImagesRef;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);


        mAuth =FirebaseAuth.getInstance();
        RootRef = FirebaseDatabase.getInstance().getReference();
        UserProfileImagesRef = FirebaseStorage.getInstance().getReference().child("Profile Images");


    InitializeFields();

        userProfileImage.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Intent galleryIntent = new Intent();
                galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
                galleryIntent.setType("image/*");
                startActivityForResult(galleryIntent, GalleryPick);
            }
        });
    }




     private void InitializeFields()
    {userProfileImage = (CircleImageView) findViewById(R.id.set_profile_image);}

     @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == GalleryPick && resultCode==RESULT_OK && data!=null)
        {
            Uri ImageUri = data.getData();
            Uri imageUri = data.getData();
            CropImage.activity(imageUri)
                    .setGuidelines(CropImageView.Guidelines.ON)
                    .setAspectRatio(1,1)
                    .start(this);
            return;

        }

       if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE)
       {
            CropImage.ActivityResult result = CropImage.getActivityResult(data);

            if (resultCode == RESULT_OK)
            {
                Uri resultUri = result.getUri();

                StorageReference filePath = UserProfileImagesRef.child(".jpg");
                filePath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task)
                    {
                        if (task.isSuccessful())
                        {
                            Toast.makeText(SettingsActivity.this, "Profile Image Uploaded Successfully!", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }

       }


    }


Logcat is given below :


2020-03-26 20:21:57.216 29321-30259/com.assignment.messageit E/StorageException: StorageException has occurred.
    Object does not exist at location.
     Code: -13010 HttpResult: 404
2020-03-26 20:21:57.223 29321-30259/com.assignment.messageit E/StorageException: The server has terminated the upload session
    java.io.IOException: The server has terminated the upload session
        at com.google.firebase.storage.UploadTask.serverStateValid(com.google.firebase:firebase-storage@@19.1.1:331)
        at com.google.firebase.storage.UploadTask.shouldContinue(com.google.firebase:firebase-storage@@19.1.1:300)
        at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@19.1.1:221)
        at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@19.1.1:1072)
        at com.google.firebase.storage.StorageTask$$Lambda$12.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:919)
     Caused by: java.io.IOException: {  "error": {    "code": 404,    "message": "Not Found.  Could not access bucket messageit-1246f.appspot.com",    "status": "ACCESS_BUCKET"  }}
        at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@19.1.1:433)
        at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@19.1.1:450)
        at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@19.1.1:441)
        at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@19.1.1:272)
        at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@19.1.1:286)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@19.1.1:70)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@19.1.1:62)
        at com.google.firebase.storage.UploadTask.sendWithRetry(com.google.firebase:firebase-storage@@19.1.1:467)
        at com.google.firebase.storage.UploadTask.beginResumableUpload(com.google.firebase:firebase-storage@@19.1.1:268)
        at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@19.1.1:216)
        at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@19.1.1:1072) 
        at com.google.firebase.storage.StorageTask$$Lambda$12.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:919) 
2020-03-26 20:21:57.223 29321-30259/com.assignment.messageit E/StorageException: StorageException has occurred.
    Object does not exist at location.
     Code: -13010 HttpResult: 404
2020-03-26 20:21:57.228 29321-30259/com.assignment.messageit E/StorageException: The server has terminated the upload session
    java.io.IOException: The server has terminated the upload session
        at com.google.firebase.storage.UploadTask.serverStateValid(com.google.firebase:firebase-storage@@19.1.1:331)
        at com.google.firebase.storage.UploadTask.shouldContinue(com.google.firebase:firebase-storage@@19.1.1:300)
        at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@19.1.1:221)
        at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@19.1.1:1072)
        at com.google.firebase.storage.StorageTask$$Lambda$12.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:919)
     Caused by: java.io.IOException: {  "error": {    "code": 404,    "message": "Not Found.  Could not access bucket messageit-1246f.appspot.com",    "status": "ACCESS_BUCKET"  }}
        at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@19.1.1:433)
        at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@19.1.1:450)
        at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@19.1.1:441)
        at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@19.1.1:272)
        at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@19.1.1:286)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@19.1.1:70)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@19.1.1:62)
        at com.google.firebase.storage.UploadTask.sendWithRetry(com.google.firebase:firebase-storage@@19.1.1:467)
        at com.google.firebase.storage.UploadTask.beginResumableUpload(com.google.firebase:firebase-storage@@19.1.1:268)
        at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@19.1.1:216)
        at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@19.1.1:1072) 
        at com.google.firebase.storage.StorageTask$$Lambda$12.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:919) 

  • Maybe this helps you: https://stackoverflow.com/questions/42982147/storageexception-has-occurred-object-does-not-exist-at-location-storage-fireba – Yonggan Mar 25 '20 at 13:17
  • 1
    Are you sure you are getting the data from the right path? Show us the Storage path. – Alex Mamo Mar 25 '20 at 13:27
  • I've added the code separately for storage of the pic to Firebase Storge – Shrayan Bandyopadhyay Mar 25 '20 at 13:40
  • Please look at the edit @AlexMamo – Shrayan Bandyopadhyay Mar 25 '20 at 14:22
  • What the value of `UserProfileImagesRef` and `currentUserId`? Cannot see any picture of your storage path. – Alex Mamo Mar 25 '20 at 14:24
  • 1
    I highly recommend getting out of the habit of catching exceptions and showing them in a toast, as it makes debugging harder. Instead either log the exception (with `Log.e` or `Log.w`) or just let it go and crash the app. In either case the exception message will be written to the logcat output of your app, where you can see both the message and (equally importantly) the stack trace of exactly where the error occurred. This makes it easier to pinpoint the problem yourself, and to share the message+stacktrace in your question. – Frank van Puffelen Mar 25 '20 at 14:41
  • UserProfileImagesRef = FirebaseStorage.getInstance().getReference().child("Profile Images"); – Shrayan Bandyopadhyay Mar 25 '20 at 14:49
  • currentUserId = mAuth.getCurrentUser().getUid(); – Shrayan Bandyopadhyay Mar 25 '20 at 14:49
  • Is this what you want? @AlexMamo – Shrayan Bandyopadhyay Mar 25 '20 at 15:11
  • The error shown is : Caused by: java.io.IOException: { "error": { "code": 404, "message": "Not Found. Could not access bucket messageit-1246f.appspot.com", "status": "ACCESS_BUCKET" }} – Shrayan Bandyopadhyay Mar 25 '20 at 15:58
  • @FrankvanPuffelen Im here with the error. Please Review – Shrayan Bandyopadhyay Mar 26 '20 at 09:45
  • @Annonymous-sys There's just too much code here for us to efficiently help. I find myself scrolling up and down through the code looking for where it may becoming from, which is not a great use of time. Please reproduce the problem in a minimal amount of code that any of us can run, and then update your question to show only that code, the error message you get, and the full stack trace. For more guidance on this, see [how to create a minimal, complete, verifiable example](http://stackoverflow.com/help/mcve) – Frank van Puffelen Mar 26 '20 at 13:32
  • @FrankvanPuffelen Hello sir, I've tried tried my best to reduce the code and provide the complete Logcat. Hope you could deduce the error. Let me inform you that i have created the firebase cloud storage in the firebase database. I'm sorry for being a complete noob or silly. I'm not that sure footed into every aspect of developing. – Shrayan Bandyopadhyay Mar 26 '20 at 15:05
  • It looks like your Cloud Storage bucket doesn't yet exist. Did you open the [Storage panel](https://console.firebase.google.com/u/0/project/_/storage) in the Firebase console yet? – Frank van Puffelen Mar 26 '20 at 16:11
  • @FrankvanPuffelen Yes i did. I was prompted a get started option. I followed it. and created the cloud storage. – Shrayan Bandyopadhyay Mar 26 '20 at 16:31
  • these are my rules: rules_version = '2'; service firebase.storage { match /b/{bucket}/o { match /{allPaths=**} { allow read, write: if request.auth != null; } } } – Shrayan Bandyopadhyay Mar 26 '20 at 16:32
  • @FrankvanPuffelen Were you able to find anything else related to the problem – Shrayan Bandyopadhyay Mar 27 '20 at 13:44
  • @ShrayanBandyopadhyay Were you able to solve the issue? If yes, please share the solution. – Sushan Sapaliga Jul 12 '21 at 06:49
  • @SushanSapaliga No i was unable to sole the problem. – Shrayan Bandyopadhyay Oct 10 '21 at 07:13

0 Answers0