0
const [ExcelData,setExcelData]=useState({})
    const {id}=useParams()
    useEffect(() => {
        const fetchFile = async () => {
            
            const response = await getFileFromAppWrite(id)
            console.log('lioa', response)
            
            const reader = new FileReader();
            reader.onload = (e) => {
           
           const value=e.target?.result 
          const data = new Uint8Array(value);
          const workbook = read(data, { type: 'array' });
          const worksheet = workbook.Sheets[workbook.SheetNames[0]];
                  const json = utils.sheet_to_json(worksheet, { header: 1 });
                
            };
          
        reader.result(response);
        }
        fetchFile()
    }, [id])`
//these are upload get file from appwrite function

export const uploadFile = (file: any) => {
   
    const promise = storage.createFile("excel1", file.name, file);
    promise.then(function (response) {
    message.success("fileUploaded succesfull"); // Success
}, function (error) {
    message.error("File Not Uploaded !") // Failure your text
});
};

`export const getFiles = async () => {

    try {
        const response = await storage.listFiles('excel1');
        
            return response
    
    } catch (error) {
        throw error
}

}

export const getFileFromAppWrite = async (fileId:any) => {
  try {
    const response = await storage.getFile("excel1",fileId);
    return response // Returns the file data
  } catch (error) {
    console.log('Error retrieving the file from Appwrite:', error);
    throw error;
  }
};`

as i want to read data from xlsx file which is getting from appwrite i am getting error in reader.result(response); That file is Cannot invoke an object which is possibly 'null'.ts(2721) This expression is not callable. No constituent of type 'string | ArrayBuffer' is callable.ts(2349) (property) FileReader.result: string | ArrayBuffer | null

0 Answers0