Skip to content
Back

Upload Avatar to storage. (Node.JS)

  • 0
  • Functions
  • Avatars
  • Storage
kamal.panara
21 Jul, 2023, 13:33

check this

TL;DR
User was having an issue with uploading avatars to storage in a Node.JS application. They were able to fix the problem by removing the file with the SDK instead of the console. However, they noticed that even after changing the `userName`, the old file was still being shown. The user shared a code snippet that seems to be working. Another user suggested using the Appwrite SDK and provided updated code. The user confirmed that the updated code worked and thanked the helper.
kamal.panara
21 Jul, 2023, 13:33

is it same in your code?

kamal.panara
21 Jul, 2023, 13:34

/files/${fileId}

BugProg
21 Jul, 2023, 13:34

yes

kamal.panara
21 Jul, 2023, 13:34

hmm

BugProg
21 Jul, 2023, 13:34

I have this:

TypeScript
      const response = await fetch(
        `https://cloud.appwrite.io/v1/storage/buckets/${bucketId}/${fileId}`,
        requestOptions
      ); // here is var
BugProg
21 Jul, 2023, 13:34

ho almost

BugProg
21 Jul, 2023, 13:35

I copied the updated code quickly

kamal.panara
21 Jul, 2023, 13:35
TypeScript
const response = await fetch(
        `https://cloud.appwrite.io/v1/storage/buckets/${bucketId}/files/${fileId}`,
        requestOptions
      ); // here is var
kamal.panara
21 Jul, 2023, 13:35

use this

BugProg
21 Jul, 2023, 13:36

Same error

kamal.panara
21 Jul, 2023, 13:37

ok

kamal.panara
21 Jul, 2023, 13:37

let use appwrite sdk

kamal.panara
21 Jul, 2023, 13:37

let me test it on my project then i will share the code.

BugProg
21 Jul, 2023, 13:38

Ho, thank you !

BugProg
21 Jul, 2023, 14:15
TypeScript
avatars.getInitials(userName, 64, 64).then((buffer) => {
  fs.writeFile("image.png", buffer, (err) => {
    if (!err) {
      sharp("image.png").toFile("output.png", (err, info) => {
        if (!err) {
          console.log("Image was successfully converted:", info);
          storage.createFile(
            bucketId,
            "MyFidddleID",
            sdk.InputFile.fromPath("output.png", "Tesdst.png")
          );
        }
      });
    }
  });
});
BugProg
21 Jul, 2023, 14:15

This code seems to work !!!!

BugProg
21 Jul, 2023, 14:15

Thank you for your help 🙂

BugProg
21 Jul, 2023, 14:17

One thing strange if I execute the code, remove the file in Appwrite storage re-execute the code after changing the userName I get the old file

kamal.panara
21 Jul, 2023, 16:44

Cool

kamal.panara
21 Jul, 2023, 16:44

Maybe due to cache image data on your frontend.

kamal.panara
21 Jul, 2023, 16:45

Or it shows same on storage console too?

BugProg
22 Jul, 2023, 10:26

No it shows the same on the console.

BugProg
22 Jul, 2023, 10:26

I was able to fix the problem by remove the file with the sdk not from the console

kamal.panara
22 Jul, 2023, 10:41

Okay

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