0

everyone. I want to upload multiple images to Firebase Storage. These are in my gallery and the user can choose from these 6 images in total. After clicking on a button, all images should be loaded into the storage one after the other and the respective download URL should be returned. If I try the whole thing with the following code, I run into the addOnFailureListener() method with the log output:

com.google.firebase.storage.StorageException: An unknown error occurred, please check the HTTP result code and inner exception for server response.

What could be the mistake? Thank you very much!

val storage = Firebase.storage
val storageRef = storage.reference

 private fun uploadImages() {

    val progressDialog = ProgressDialog(context).apply {
        setTitle("Uploading Picture....")
        setCancelable(false)
        setCanceledOnTouchOutside(false)
        show()
    }
    
    
    for (i in 0 until listImg.size) {

        var file = Uri.fromFile(File(listImg[i].toString()))
        val riversRef = storageRef.child("images/${file.lastPathSegment}")
        var uploadTask = riversRef.putFile(file)


        uploadTask.addOnProgressListener { taskSnapshot  ->
            val progress = (100.0 * taskSnapshot.bytesTransferred) / taskSnapshot.totalByteCount
            Log.d("TAG", "Upload is $progress% done")
            progressDialog.setMessage("Uploaded.. " + progress.toInt() + "%")

        }.addOnPausedListener {
            Log.d("TAG", "Upload is paused")
        }.addOnFailureListener {
            Log.e("ERROR:",it.toString())
            progressDialog.dismiss()
        }.addOnSuccessListener {
            progressDialog.dismiss()
            val uri = riversRef.downloadUrl

            Log.d("DownloadURL:" ,uri.toString())
        }


    }

 }

This is the path to the respective file in which is in the list:

enter image description here

My Rules on Firebase Storage:

enter image description here

I have the following dependencies:

implementation platform('com.google.firebase:firebase-bom:31.1.1')
implementation 'com.google.firebase:firebase-storage-ktx'

I have the following dependencies:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Captai-N
  • 1,124
  • 3
  • 15
  • 26
  • Does this [answer](https://stackoverflow.com/a/59093116/5246885) help? Since you're using Kotlin, I think that this [resource](https://medium.com/firebase-tips-tricks/how-to-upload-an-image-to-cloud-storage-and-save-the-url-in-firestore-42711ca1df46) will help. Here is the corresponding [repo](https://github.com/alexmamo/CloudStorageJetpackCompose). – Alex Mamo Dec 22 '22 at 07:42

0 Answers0