Back

getFilePreview problem

  • 0
  • Web
Carre
15 Jun, 2024, 08:40

How can i fix it?

TL;DR
Issue with using `ImageGravity` enum as a parameter in `getFilePreview` function from Appwrite SDK. The enum value should match the parameter type. Change 'top' to `ImageGravity.Top` to resolve the error. Also, ensure to update the SDK to the latest version for compatibility with the enum.
darShan
15 Jun, 2024, 08:44

ig it should take a string. whats the error if you hover over the red lines? I don't see this issue.

darShan
15 Jun, 2024, 08:45

also, whats the sdk version?

Carre
15 Jun, 2024, 08:45
Carre
15 Jun, 2024, 08:46

"dependencies": { "@hookform/resolvers": "^3.6.0", "@radix-ui/react-label": "^2.0.2", "@radix-ui/react-slot": "^1.0.2", "@radix-ui/react-toast": "^1.1.5", "@tanstack/react-query": "^5.45.0", "@tanstack/react-query-devtools": "^5.45.0", "appwrite": "^15.0.0", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", "lucide-react": "^0.394.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-dropzone": "^14.2.3", "react-hook-form": "^7.51.5", "react-intersection-observer": "^9.10.3", "react-router-dom": "^6.23.1", "tailwind-merge": "^2.3.0", "zod": "^3.23.8" },

Carre
15 Jun, 2024, 08:47

error TS2345: Argument of type '"top"' is not assignable to parameter of type 'ImageGravity | undefined'.

darShan
15 Jun, 2024, 08:47
TypeScript
import {Client, ImageGravity, Storage} from 'appwrite';

const fileUrl = await storage.getFilePreview(
  bucketId,
  fileId,
  2000,
  2000,
  ImageGravity.Top, // <<
  100
);
darShan
15 Jun, 2024, 08:47

this should work.

Carre
15 Jun, 2024, 08:48

Wow, thanks

Carre
15 Jun, 2024, 08:48

its not red now atleast

darShan
15 Jun, 2024, 08:49

no worries :appwritecheers:.

Carre
15 Jun, 2024, 08:49

do you know why any is red here?

darShan
15 Jun, 2024, 08:49

should be string[] i think.

Carre
15 Jun, 2024, 08:50

const queries[]: ?

darShan
15 Jun, 2024, 08:50

const queries: string[] = ...

darShan
15 Jun, 2024, 08:51

Query.* builders return string.

Carre
15 Jun, 2024, 08:52

Thanks, one last question. Do you know why this is red?

darShan
15 Jun, 2024, 08:52

hover over the errors so I can see the actual error.

Carre
15 Jun, 2024, 08:53
Carre
15 Jun, 2024, 08:54
darShan
15 Jun, 2024, 08:55

not an expert in this, but most probably the params could be wrong ig. the function overloads doesn't expect/support what you've passed.

Carre
15 Jun, 2024, 08:57

Okey, will try to fix it. Thanks for the help!

Carre
15 Jun, 2024, 08:58

Are you good with building apps?

darShan
15 Jun, 2024, 08:59

the apps I make, work fine, so ig yess? 🤣 only experienced in native though, no react and stuff.

darShan
15 Jun, 2024, 08:59

btw, please mark the post title as [SOLVED] if your issues are resolved.

Happy Appwriting :appwritecheers:.

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