代码之家  ›  专栏  ›  技术社区  ›  Diaz diaz

从FireStore获取所有图像URL

  •  0
  • Diaz diaz  · 技术社区  · 7 年前

    我想用 Firestore . 我需要获取存储在文件夹中的所有图像URL 火店 . 我正在跟踪 This .

    使用时:

    db.collection("images")
        .get()
        .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                if (task.isSuccessful()) {
                    for (QueryDocumentSnapshot document : task.getResult()) {
                        Log.d(TAG, document.getId() + " => " + document.getData());
                    }
                } else {
                    Log.w(TAG, "Error getting documents.", task.getException());
                }
            }
        });
    

    我得到下面的错误。

    最初我在

    程序类型已经存在:com.google.common.annotations.gwtcompatible

    通过以下方式解决:

    implementation ("com.google.firebase:firebase-firestore:17.0.3"){
        exclude group: 'com.google.guava'
    }
    
    java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
        at com.google.firebase.firestore.g.zza.zzb(SourceFile:324)
        at com.google.firebase.firestore.g.zzd.run(Unknown Source:2)
        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)
     Caused by: java.lang.NoSuchMethodError: No static method checkArgument(ZLjava/lang/String;I)V in class Lcom/google/common/base/Preconditions; or its super classes (declaration of 'com.google.common.base.Preconditions' appears in /data/app/com.apps.dp-2wjpiDlhe60_b_F7OtfpaQ==/split_lib_dependencies_apk.apk!classes2.dex)
        at com.google.firebase.Timestamp.zza(SourceFile:136)
        at com.google.firebase.Timestamp.<init>(SourceFile:47)
        at com.google.firebase.firestore.d.zzm.<clinit>(SourceFile:12)
        at com.google.firebase.firestore.c.zzav.<init>(SourceFile:24)
        at com.google.firebase.firestore.c.zzat.zzb(SourceFile:104)
        at com.google.firebase.firestore.c.zzi.<init>(SourceFile:125)
        at com.google.firebase.firestore.b.zzf.zza(SourceFile:1215)
        at com.google.firebase.firestore.b.zzh.run(Unknown Source:8)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at com.google.firebase.firestore.g.zza$zza.run(SourceFile:190)
        at java.lang.Thread.run(Thread.java:764)
        07-26 09:56:29.396 25793-25793/com.apps.dp E/UncaughtException: 
        java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
        at com.google.firebase.firestore.g.zza.zzb(SourceFile:324)
        at com.google.firebase.firestore.g.zzd.run(Unknown Source:2)
        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)
     Caused by: java.lang.NoSuchMethodError: No static method checkArgument(ZLjava/lang/String;I)V in class Lcom/google/common/base/Preconditions; or its super classes (declaration of 'com.google.common.base.Preconditions' appears in /data/app/com.apps.dp-2wjpiDlhe60_b_F7OtfpaQ==/split_lib_dependencies_apk.apk!classes2.dex)
        at com.google.firebase.Timestamp.zza(SourceFile:136)
        at com.google.firebase.Timestamp.<init>(SourceFile:47)
        at com.google.firebase.firestore.d.zzm.<clinit>(SourceFile:12)
        at com.google.firebase.firestore.c.zzav.<init>(SourceFile:24)
        at com.google.firebase.firestore.c.zzat.zzb(SourceFile:104)
        at com.google.firebase.firestore.c.zzi.<init>(SourceFile:125)
        at com.google.firebase.firestore.b.zzf.zza(SourceFile:1215)
        at com.google.firebase.firestore.b.zzh.run(Unknown Source:8)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at com.google.firebase.firestore.g.zza$zza.run(SourceFile:190)
        at java.lang.Thread.run(Thread.java:764)
    

    从过去的6个小时开始,我一直在努力。我能得到一些帮助吗?我还有一个问题,是否可以使用 火店 Android中的API。或者我先将这些URL保存在FireBase数据库中?已经签出了一些关于这个的帖子 Like this one 这说明这是不可能的。

    1 回复  |  直到 7 年前
        1
  •  3
  •   Alex Mamo    7 年前

    根据您最后的评论,请注意,为了检索托管在 Cloud Storage for Firebase ,你需要知道 path download URL . 不知道从文件夹中获取所有文件是不可能的。

    为了解决这个问题,我建议在上载任何文件时,存储 下载网址 到数据库 Firebase Real-time Database 还是新的 Cloud Firestore . 请参阅下面的一个简单示例 下载网址 .

    storageRef.child("YourFolderName").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
        @Override
        public void onSuccess(Uri uri) {
            // Got the download URL for "YourFolderName/YourFile.pdf"
            // Add it to your database
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            // Handle any errors
        }
    });
    

    最后只需查询 url 来自FireBase实时数据库或 网址 从云FireStore收集并在需要时使用它们。