Back

`storage.createFile` throws `source.on is not a function` error

  • 0
  • Web
  • Storage
manazo
31 Aug, 2023, 11:35

Hey guys. So I'm trying to upload an image using storage.createFile. But when I run it, it throws source.on is not a function. Below is what my function looks like

TypeScript
async function uploadAvatar(file: File, userId: string) {
  const { Permission, Role } = await import("appwrite");
  const { storage } = await import("@/AppwriteServices");
  const { Bucket_ID } = await import("@/AppwriteServices/IDs");

  await storage.createFile(Bucket_ID, userId, file, [
    Permission.delete(Role.user(userId)),
    Permission.update(Role.user(userId)),
    Permission.read(Role.any()),
  ]);
}

the screenshot shows the error

Any idea what's happening?

TL;DR
The user is facing an error when trying to upload an image using `storage.createFile`. The error message is `source.on is not a function`. It seems like the code is executing on the server side and the file is obtained from user input. The server version is not mentioned, but the SDK version is 11.0.0. The user is requesting help in understanding the issue. Possible Solution: It seems that the web SDK cannot be used for creating a file server-side in this manner. There could be differences between files in the browser and files in Node.js.
Drake
31 Aug, 2023, 19:52

what server version? what SDK version? Is this executed client side? how are you getting that file?

manazo
31 Aug, 2023, 21:59

Server: Cloud Console SDK: 11.0.0 It's executing on the server side and I'm getting that file from user input

Drake
31 Aug, 2023, 22:20

seems like you can't use the web sdk for creating a file server side like this. files in the browser are different than files in nodejs

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