异步任务跟不上for循环(firebase)

问题描述 投票:1回答:1
  for (Uri mUri : mSelected) 
   {
       imagesRef = storageRef.child(postid + mUri.getLastPathSegment());
       imagesRef.putFile(mUri).addOnSuccessListener(task4 ->
       db.collection("posts").document(postid).update("photo_id", FieldValue.arrayUnion(imagesRef.getDownloadUrl())));
   }

所以,现在我正在使用Firestore和Firebase存储。我将(多个)图像上传到存储中,上传后,我获得了下载网址,并希望将其添加到我的Firestore中。因此,问题在于,仅将最后一个图像添加到Firestore中,所有图像都添加到存储中,但是仅将最后一个imgUrl添加到Firestore中。由于Firebase使用异步任务,我怀疑这是因为更新任务无法跟上循环。非常感谢任何帮助!

for(Uri mUri:mSelected){imagesRef = storageRef.child(postid + mUri.getLastPathSegment()); imagesRef.putFile(mUri).addOnSuccessListener(task4-> db.collection(“ posts”)....

android firebase loops asynchronous android-asynctask
1个回答
1
投票

我认为问题可能出在imagesRef

© www.soinside.com 2019 - 2024. All rights reserved.