rishavOriginal post
Web Developer
Hi, I am trying to upload the file, but I an unable to do so.
Kindly assist
const uploadFile = async (filePath) => {
try {
if (!fs.existsSync(filePath)) {
throw new Error("File does not exist: " + filePath);
}
// console.log(fs.readFileSync(filePath));
// ("/fix");
// Upload file with InputFile
const resultUpload = await storage.createFile(
"__",
ID.unique(),
InputFile.fromPath("./images.jpeg", "images.jpeg"),
[
Permission.read(Role.any()),
Permission.update(Role.users()),
Permission.delete(Role.users()),
]
);
console.log(resultUpload);
// console.log("File uploaded successfully:", resultUpload);
return resultUpload;
} catch (error) {
console.error("Error uploading file:", error);
}
};
Summary
Developer is trying to upload a file but encountering a 'Cannot read properties of undefined (reading 'fromPath')' TypeError.
To resolve this, they should check the path being passed to InputFile.fromPath() to ensure it is correct and contains a valid file.