Back

Error uploading file: TypeError: Cannot read properties of undefined (reading 'fromPath')

  • 0
  • Storage
rishav
2 Feb, 2025, 08:15

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); }

TypeScript
// 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); } };

TL;DR
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.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more