How to generate link of uploaded file in react with token and time stamp to the firebase

Using this Methode we can generate the link in firebase to any file with token id and time stamp

  const generateFileURLs = async (files) => {
    const uploadedFileLinks = files.map(async (file) => {
      // Generate a unique filename using the current timestamp
      const timestamp = new Date().getTime();
      const filename = `${timestamp}_${file.name}`;
  
      // Assuming storageRef is your Firebase storage reference
      const storageRef = ref(storage, 'Uploads');
      const fileRef = ref(storageRef, filename); // Create a reference to the file with the new filename
  
      // Assuming you have a function uploadBytesToStorage that uploads file to storage
      await uploadBytes(fileRef, file);
  
      // Get the download URL for the uploaded file
      const downloadURL = await getDownloadURL(fileRef);
      return downloadURL;
    });
  
    try {
      const uploadedFileURLs = await Promise.all(uploadedFileLinks);
      return uploadedFileURLs;
    } catch (error) {
      console.error('Error uploading files:', error);
      throw error;
    }
  };

Leave a comment

Your email address will not be published. Required fields are marked *