I using FileReader and I am trying but I got only getting FileName and FileFormat.
However, I couldn't How to get folderName Soma07
There are several modules available but I don't know how to make it work in React.
Does anybody know?
Here are the examples I found:
const [fileName, setfileName] = useState("")
const upLoadImage = async (e) => {
const file = e.target.files[0]
const base64 = await convertBase64(file);
console.log(base64);
setfileName(file.name)
}
const convertBase64 = (file) => {
return new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.readAsDataURL(file);
fileReader.onload = (() => {
resolve(fileReader.result)
})
fileReader.onerror = ((error) => {
reject(error)
})
})
}
Due to security reasons browsers don't allow to get file path. JavaScript in browser has no access to the File System.