Untitled

 avatar
unknown
plain_text
a year ago
875 B
4
Indexable
 const handleFileUpload = async (event) => {
    const files = event.target.files;
    if (!files.length) return;

    setUploading(true);
    const storage = getStorage();
    const urls: string[] = [];
    const previews: string[] = [];

    for (let file of files) {
      const uniqueFileName = `${uuidv4()}_${file.name}`;
      const fileRef = storageRef(storage, `reviewsMedia/${uniqueFileName}`);
      const filePreview = URL.createObjectURL(file);
      previews.push(filePreview);

      try {
        await uploadBytes(fileRef, file);
        const url = await getDownloadURL(fileRef);
        urls.push(url);
      } catch (error) {
        console.error("Error uploading file:", error);
        setUploading(false);
        return;
      }
    }

    setImagePreviews(previews);
    onUrlsUpdated(urls);
    setUploading(false);
  };
Editor is loading...
Leave a Comment