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:
My Rules on Firebase Storage:
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"/>