为什么我要覆盖Firebase storageRef?

问题描述

我具有以下上传功能,试图将两个图像上传到Firebase并将其下载网址合并到一个集合中。

我的第二个StorageRef如何继续覆盖第一个,这导致只上传压缩图像,并且在我的收藏集中两次获得了压缩图像链接

我该如何解决

  const onUpload = async () => {
    if (file) {
      const options = {
        maxWidthOrHeight: 250,};
      const fullStorageRef = storage.ref();
      const fullFileRef = fullStorageRef.child(file.name);
      await fullFileRef.put(file);
      const fullUrl = await fullFileRef.getDownloadURL();
      const thumbnailStorageRef = storage.ref();
      const compressedFile = await imageCompression(file,options);
      const compressedFileRef = thumbnailStorageRef.child(compressedFile.name);
      await compressedFileRef.put(compressedFile);
      const thumbnailUrl = await compressedFileRef.getDownloadURL();
      db.collection("images").add({
        created: firebase.firestore.FieldValue.serverTimestamp(),full: fullUrl,thumbnail: thumbnailUrl,});
      setFile(null);
    }
  };

解决方法

file.name和compressedFile.name相同