Back

storage.getFilePreview returning arraybuffer

  • 0
  • Storage
Brinamite
23 May, 2024, 21:53

Did the return type from this function get changed? I referenced an older project of mine and this returns a URL to the generated preview.

I am using NextJS with a server-side API that serves this URL. Now that it is an ArrayBuffer (or I am doing something wrong with it to become as such), what's the neatest way to serve it to my client apps?

The console log of my awaited output:

TypeScript
{
  fileUrl: ArrayBuffer {
    [Uint8Contents]: <ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 00 00 00 00 00 ff fe 00 25 43 72 65 61 74 65 64 20 62 79 20 66 43 6f 64 65 72 20 47 72 61 70 68 69 63 20 50 72 6f 63 65 73 73 6f 72 ff db 00 43 00 06 04 05 06 05 04 06 06 05 06 07 07 06 08 0a 10 0a 0a 09 09 0a 14 0e 0f 0c 10 17 14 18 18 17 14 16 16 1a 1d ... 35663 more bytes>,
    byteLength: 35763
  }
}

PS I didnt forget to format my code this time 🙂

TL;DR
The `getFilePreview` function now returns an ArrayBuffer instead of a URL. To serve it to client apps, you can convert the ArrayBuffer to a Blob and create a URL for it using `URL.createObjectURL(new Blob([arrayBuffer]))`.
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