async function gatherFilesInfo(postId, fileInputs) {
const postRef = doc(db, 'posts', postId);
const postSnapshot = await getDoc(postRef);
if (!postSnapshot.exists()) {
console.error('Document does not exist!');
return [];
}
const postData = postSnapshot.data();
let existingFiles = postData.files || [];
let newFilesData = existingFiles.map(file => ({ ...file }));
for (let i = 0; i < fileInputs.length; i++) {
const fileInput = fileInputs[i];
if (fileInput && fileInput.files && fileInput.files.length > 0) {
const file = fileInput.files[0];
const storageRef = ref(storage, `posts/${postId}/files/${file.name}`);
const uploadResult = await uploadBytes(storageRef, file);
const newUrl = await getDownloadURL(uploadResult.ref);
newFilesData[i] = { name: file.name, url: newUrl, isEmpty: false };
} else {
if (!existingFiles[i] || existingFiles[i].isEmpty) {
newFilesData[i] = { name: 'nofile', url: '', isEmpty: true };
}
}
}
}
<div class="fileup">
<label for="file1">· paper </label>
<input type="file" id="file1" class="file-input"/>
<span id="file-name1" style="color: blue;">nofilenow</span>
<span id="refile-name1" style="display: none; color: red;"></span>
<label for="file1" class="file-label">upload</label>
</div> //it has 0~17 number
It’s a function to edit what you write,
Number 1 from 0 to 17 has a file
If you have added numbers 2 and 3, you will update files 2 and 3.
If number 1 is not selected, number 1 is left without updating it. It seems that even if I select a file in the input, it doesn’t detect it at all
1