Back

getFilePreview returns ByteCode

  • 0
  • Cloud
Grahf
28 Mar, 2025, 00:38

I'm running this code:

TypeScript
  blah = await storage.getFilePreview(
    import.meta.env.NEWS_IMAGES_ID,
    news.imageId,
    0, // width (optional)
    0, // height (optional)
    ImageGravity.Center, // gravity (optional)
    0, // quality (optional)
    0, // borderWidth (optional)
    'fff', // borderColor (optional)
    0, // borderRadius (optional)
    0, // opacity (optional)
    -360, // rotation (optional)
    'fff', // background (optional)
    ImageFormat.Jpg, // output (optional)
  )
  console.log('we have img: ', blah)

And I get ArrayBuffer { [Uint8Contents]: <ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 48 00 48 00 00 ff db 00 43 00 03 02 02 02 02 02 03 02 02 02 03 03 03 03 04 06 04 04 04 04 04 08 06 06 05 06 09 08 0a 0a 09 08 09 09 0a 0c 0f 0c 0a 0b 0e 0b 09 09 0d 11 0d 0e 0f 10 10 11 10 0a 0c 12 13 12 10 13 0f 10 10 10 ff db 00 43 01 03 03 03 04 03 04 ... 66367 more bytes>, byteLength: 66467 }

The docs seem to indicate I should have a image url

TL;DR
Developers are confused about the outcome of `getFilePreview` as it should return an image URL but instead, it returns Binary Data. The resolved solution is to convert the Binary Data to a Base64 encoded URL as an image preview link.
Steven
28 Mar, 2025, 00:42

what docs are you referring to?

Grahf
28 Mar, 2025, 00:43

It says: console.log(result.href);

Grahf
28 Mar, 2025, 00:58

I guess every image in a bucket has a standard url:

TypeScript
`https://cloud.appwrite.io/v1/storage/buckets/${import.meta.env.NEWS_IMAGES_ID}/files/${news.imageId}/view?project=${import.meta.env.PUBLIC_APPWRITE_PROJECT}`
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