Back

c# GetFile, GetFilePreview

  • 0
  • Self Hosted
  • General
  • Storage
Hohenheim
25 Nov, 2023, 21:48

I use C# Appwrite 0.7 package, and I’m on Appwrite 1.14, I try to get a file from a bucket using

var storage = new Storage(client); File result = await storage.GetFile( bucketId: "[BUCKET_ID]", fileId: "[FILE_ID]");

it return the file in result, but I haven’t found the method to show it in picture box, I found some old doc using file.Content, but it doesn’t work anymore. After this I tried to get a preview using

var storage = new Storage(client); byte[] result = await storage.GetFilePreview( bucketId: "[BUCKET_ID]", fileId: "[FILE_ID]");

but this time, I get result=null, and it’s the same thing for: GetFileView, or GetFileDownload. Please help, I’m struggling, I would like to use GetFile and GetFilePreview, all the files are jpg images, and under 5mo. Thanks a lot

TL;DR
The user is trying to display an image from a bucket using the C# Appwrite 0.7 package. They have tried using the `GetFile` and `GetFilePreview` methods, but are encountering some issues. Solution: The user should check the following: 1. Make sure the `GetFile` method is returning a valid file by checking if `result` is null or not. 2. When accessing the content of the file, use `result.Content.Data` instead of `Encoding.UTF8.GetBytes(result.Content)`. 3. Ensure that the `GetFilePreview` method is returning a non-null value for `result
Drake
26 Nov, 2023, 02:40

In general, how do you handle images in your tech stack?

Hohenheim
27 Nov, 2023, 04:18

before appwrite, i was using sql server, putting images directly in the db, now, i tried to use var storage = new Storage(client); File result = await storage.GetFile( bucketId: "[BUCKET_ID]", fileId: "[FILE_ID]"); byte[] file = Encoding.UTF8.GetBytes(result.Content); //here the problem, no content if (result != null) using (MemoryStream stream = new MemoryStream(file)) { Image image = Image.FromStream(stream); picDocument.Image = image; }

Hohenheim
27 Nov, 2023, 04:21

and with this : var storage = new Storage(client); byte[] result = await storage.GetFilePreview( bucketId: "[BUCKET_ID]", fileId: "[FILE_ID]"); if (result != null) //result is always null { Image image = Image.FromStream(stream); picDocument.Image = image; }

Hohenheim
27 Nov, 2023, 04:21

thanks for your help

Hohenheim
6 Dec, 2023, 06:35

Any help please, I'm struggling, thanks

Drake
6 Dec, 2023, 09:39

before appwrite, i was using sql server, putting images directly in the db,

And then?

Drake
6 Dec, 2023, 09:39

please also make sure you format multiline code with backticks like you would in markdown

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