[Firebase] Object does not exist at location.

유정현·2023년 3월 22일
0

Android Firebase를 사용해 이미지를 가져오는데 에러가 발생했다

StorageException has occurred.
Object does not exist at location.

{  "error": {    "code": 404,    "message": "Not Found."  }}
java.io.IOException: {  "error": {    "code": 404,    "message": "Not Found."  }}

원인
1. Firebase Storage에 찾으려는 이미지가 없을 경우
2. 이미지 명칭이나 확장자를 잘못 입력한 경우

나의 경우는 Firebase Storage에 찾으려는 이미지가 없는 경우였다..
Server측에서 DB에 임의로 넣은 이미지와 Firebase Storage의 이미지를 같이 Response 받았는데 그걸 모두 파이어베이스 이미지 처리를 해버렸다,,,

var fbStorage : FirebaseStorage?= null
fbStorage = FirebaseStorage.getInstance()
var storageRef = fbStorage?.reference?.child(받은 이미지)

storageRef?.downloadUrl?.addOnCompleteListener {
                Glide.with(context!!)
                    .load(it.result)
                    .centerCrop()
                    .into(이미지 넣을 곳)
}

[수정]
Server측에서 DB에 임의로 넣은 이미지와 Firebase Storage의 이미지를 어떻게 구별해 화면에 띄울까하고 서치를 하다가 함께 개발하는 분이 다음과 같은 방법을 제안해 진행했다.
startsWith를 사용해 특정 문자로 시작하는지 확인해 이미지를 띄워주기로 했다.

if (img.startsWith("http")){ // Server측에서 DB에 임의로 넣은 이미지
                Glide.with(this)
                    .load(img)
                    .centerCrop()
                    .circleCrop()
                    .into(binding.iv)
            }else { // Firebase Storage의 이미지
                var storeageRef = fbStorage?.reference?.child(img)
                storeageRef?.downloadUrl?.addOnCompleteListener {
                    if (it.isSuccessful) {
                        Glide.with(this)
                            .load(img)
                            .centerCrop()
                            .circleCrop()
                            .into(binding.iv)
                    }
                }
            }

0개의 댓글