Я использую kotlin / android и хранилище Firebase, до того, когда я хотел загрузить изображение в хранилище Firebase, оно работало хорошо. но недавно я получаю ошибку. Я ищу много в stackoverflow, и я нашел этот вопрос, который похож на мой, но не было никакого ответа на это:
StorageException произошла. Невозможно загрузить изображения в firebase
Вот моя ошибка:
E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 0
StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 0
E/AndroidRuntime: FATAL EXCEPTION: FirebaseStorage-Upload-1
Process: com.example.bestplaceapp, PID: 20236
java.lang.NoSuchMethodError: No virtual method getToken(Z)Lcom/google/android/gms/tasks/Task; in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/com.example.bestplaceapp-1/base.apk)
at com.google.firebase.storage.internal.Util.getCurrentAuthToken(com.google.firebase:firebase-storage@@16.0.4:148)
at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@16.0.4:65)
at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@16.0.4:57)
at com.google.firebase.storage.UploadTask.sendWithRetry(com.google.firebase:firebase-storage@@16.0.4:457)
at com.google.firebase.storage.UploadTask.beginResumableUpload(com.google.firebase:firebase-storage@@16.0.4:257)
at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@16.0.4:198)
at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@16.0.4:1106)
at com.google.firebase.storage.StorageTask$$Lambda$12.run(com.google.firebase:firebase-storage@@16.0.4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 0
мой код работал раньше, вот мой код:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(requestCode == GALLERY_ID && resultCode == Activity.RESULT_OK){
var image: Uri = data?.data!!
// We crop the image
CropImage.activity(image)
.setAspectRatio(1, 1)
.start(this)
}
if(requestCode === CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE){
val result = CropImage.getActivityResult(data)
if(resultCode === Activity.RESULT_OK) {
// preparing image
var resultUri = result.uri
mCurrentUser = FirebaseAuth.getInstance().currentUser
var userId = mCurrentUser!!.uid
var thumbFile = File(resultUri.path)
// We compress the image and save in thumbnail field in database
var thumbBitmap = Compressor(this)
.setMaxHeight(200)
.setMaxWidth(200)
.setQuality(65)
.compressToBitmap(thumbFile)
//We upload images to firebase
var byteArray = ByteArrayOutputStream()
thumbBitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArray)
var thumbByteArray: ByteArray
thumbByteArray = byteArray.toByteArray()
var filePath = mStorageRef!!.child("user_images")
.child(userId + ".jpg")
//Create another directory for thumbnail images ( smaller, compressed images )
var thumbFilePath = mStorageRef!!.child("user_images")
.child("thumbs")
.child(userId + ".jpg")
// end of preparing image
// put main image file to firebase storage
var uploadTask_MainImage = filePath.putFile(resultUri)
uploadTask_MainImage.continueWithTask { task ->
if (!task.isSuccessful) {
task.exception?.let {
throw it
}
}
filePath.downloadUrl
}.addOnCompleteListener { task ->
if (task.isSuccessful) {
val downloadUri = task.result.toString()
// put thumbnail image file to firebase storage
var uploadTask_ThumbnailImage: UploadTask = thumbFilePath
.putBytes(thumbByteArray)
uploadTask_ThumbnailImage.continueWithTask { task ->
if (!task.isSuccessful) {
task.exception?.let {
throw it
}
}
thumbFilePath.downloadUrl
}.addOnCompleteListener { task ->
var thumbUrl = task.result.toString()
if (task.isSuccessful) {
var updateObj = HashMap<String, Any>()
updateObj.put("image", downloadUri)
updateObj.put("thumb_image", thumbUrl)
//We save the download url of main image and thumbnail image to users table in database
mDatabase!!.updateChildren(updateObj)
.addOnCompleteListener { task: Task<Void> ->
if (task.isSuccessful) {
Toast.makeText(
this, "Profile image saved!",
Toast.LENGTH_LONG
).show()
} else {
// Handle failures
// TODO
}
}
} else {
// Handle failures
// TODO
}
}
}
}
}
}
}
I используйте эти правила хранения и в моем коде пользователь должен войти в систему для сохранения изображения в хранилище:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}