'Uploading a large number of files at once
how to implement on react uploading a large number of files at a time?
i specified in input multiplu it seems to work but still does not allow to upload more than 1 file at a time
const [fileLoad, setLoadFileState] = useState(false);
const [imageState, setImageState] = useState(false);
const [image, setImage] = useState<any>([]);
const refLabel = useRef<HTMLLabelElement>(null);
const openFile = () => refLabel.current?.click();
const uploadFile = () => {}
const changeHandler = async (event: React.ChangeEvent<HTMLInputElement>) => {
filePromiseAll(event)
.then((data) =>{
console.log(data)
})
}
const filePromiseAll = async (event: React.ChangeEvent<HTMLInputElement>) => {
const filePromise:any = new Promise((resolve) => {
if(!event.target.files?.length)
return;
const files = Array.from(event.target.files);
files.forEach(file => {
if(!file.type.match('image'))
return;
const reader = new FileReader();
reader.onload = (ev: ProgressEvent<FileReader>) => {
if(ev.target)
resolve(ev.target.result);
}
reader.readAsDataURL(file);
})
})
return await Promise.all(filePromise);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
