我正在尝试使用作业计划程序将图像上传到firebase存储。在上传操作之后,我尝试使用上传任务的OnSuccessListener中的referece.setValue(downloadUrl)将下载URL写入firebase数据库。
我上传图片就像这样存储
val directory = context.getDir("images", android.content.Context.MODE_PRIVATE)
val file = File("${directory.absolutePath}/$storyKey")
file.mkdirs()
val fileUri = android.net.Uri.fromFile(java.io.File(file, "$imageName.jpg"))
val task = storageReference.child(fileUri.lastPathSegment).putFile(fileUri)
task.addOnSuccessListener { snapshot ->
imageUploadStatus = true
val downloadUrl = snapshot.downloadUrl
reference.child(key).child("downloadUrl").setValue(downloadUrl)
}.addOnFailureListener { exception ->
imageUploadStatus = false
exception.printStackTrace()
}
但是我一直在这样崩溃
E/UncaughtException: at com.google.android.gms.internal.zzelw.zzca(Unknown Source:0)
at com.google.android.gms.internal.zzelx.zzcb(Unknown Source:132)
at com.google.android.gms.internal.zzelw.zzbx(Unknown Source:263)
at com.google.android.gms.internal.zzelw.zzca(Unknown Source:0)
at com.google.android.gms.internal.zzelx.zzcb(Unknown Source:132)
at com.google.android.gms.internal.zzelw.zzbx(Unknown Source:263)
at com.google.android.gms.internal.zzelw.zzca(Unknown Source:0)
at com.google.android.gms.internal.zzelx.zzcb(Unknown Source:132)
at com.google.android.gms.internal.zzelw.zzbx(Unknown Source:263)
at com.google.android.gms.internal.zzelw.zzca(Unknown Source:0)
at com.google.android.gms.internal.zzelx.zzcb(Unknown Source:132)
at com.google.android.gms.internal.zzelw.zzbx(Unknown Source:263)
at com.google.android.gms.internal.zzelw.zzbw(Unknown Source:0)
at com.google.firebase.database.DatabaseReference.zza(Unknown Source:10)
at com.google.firebase.database.DatabaseReference.setValue(Unknown Source:7)
at com.example.images.jobs.ImageUploadJob$onRunJob$1.onSuccess(ImageUploadJob.kt:107)
at com.example.images.jobs.ImageUploadJob$onRunJob$1.onSuccess(ImageUploadJob.kt:30)
at com.google.firebase.storage.zzj.zzi(Unknown Source:13)
at com.google.firebase.storage.zzaa.run(Unknown Source:10)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)