首页 > 解决方案 > How to upload array of image links to Firestore

问题描述

I just completed a blog app that allows a user to upload a single image as a post. I am using Firestore to save the image link from Cloud Storage

final StorageReference postPath.putFile(mainImageURI).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
                  @Override
                  public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
                      if (task.isSuccessful()){
                          downloadUri = 
        task.getResult().getDownloadUrl().toString();
       Map<String, Object> map = new HashMap<>();
                    map.put("image_url", downloadUri);
                        {

However, i now intend to allow users upload multiple images for each post. Uploading the images to Cloud Storage is no problem for me. But how can i save an array of image links for one document child in Cloud Storage. I have not been able to figure this out. Please help.

标签: androidfirebasegoogle-cloud-firestorefirebase-storage

解决方案


Firestore 具有字段的数组类型。只需使用您要编写的所有 URL 的字符串填充一个 ArrayList,并将其作为文档中您要存储它的字段的值。


推荐阅读