Back

How to add query strings for Store: getFilePreview

  • 0
  • Web
Nikky
5 Sep, 2023, 14:05

How can I pass query strings in getFilePreview? I want to pass query string "output: png". The file I uploaded is svg but preview supported are only these types (jpg, png, and gif). I want to get my svg as png so I can preview it. Using Client SDK and Cloud

TL;DR
User wants to know how to add query strings for the Store: getFilePreview endpoint. They are specifically trying to convert an SVG file to PNG for preview. There is a suggested solution provided: - Look at the function signature: the `getFilePreview` function from the storage service in the appwrite SDK for web. - Pass the desired output type as a string in the `output` parameter of the function. For example: `output: "png"`. Note: The current issue seems to be related to the user's code implementation rather than a problem with the getFilePreview endpoint itself.
hamed
5 Sep, 2023, 14:28

Shouldn't it be type of string?

ideclon
5 Sep, 2023, 14:52

The output parameter is not a Query

ideclon
5 Sep, 2023, 14:54
TypeScript
storage.getFilePreview(
    appwriteConfig.bucketId,
    fileId,
    output: "png",
);
Nikky
5 Sep, 2023, 15:03

So I did a couple of that. Still throwing error

Nikky
5 Sep, 2023, 15:03

const file = storage.getFilePreview( appwriteConfig.bucketId, fileId, output: "png" );

Nikky
6 Sep, 2023, 06:29

Thanks @Steven , so I was able to do it by putting undefined to the rest of the parameters. My goal was to preview my uploaded svg file. Since svg is not supported in getFilePreview, I tried to use output assuming it will convert svg to png so I can display it. But it only converted the default icon for unsupported files. Any suggestion how I can retrieve the uploaded svg url and display the svg file? Im using Client SDK and Cloud.

Drake
6 Sep, 2023, 14:18

πŸ‘ this issue: https://github.com/appwrite/appwrite/issues/2811

Can you use the get file view API?

Nikky
6 Sep, 2023, 14:42

So I get this when I open the href from the returned data. What's the suggested way of using this to render the svg? Or how can we display svg file out from the returned data of getFileView?

Nikky
6 Sep, 2023, 15:58

Hey @Steven , yes I have tried that and it did not work.

Drake
6 Sep, 2023, 16:00

can you check the content type in the http response header?

Nikky
6 Sep, 2023, 16:10

This is when I trye to get a png vs when I get svg. Svg is that 400 Bad Request. The only thing I did was change Id between those two requests. Sorry I didnt see this in Network earlier.

Drake
6 Sep, 2023, 16:16

Maybe just open the url in your browser and check the response headers

Nikky
6 Sep, 2023, 16:20

Oh you mean this?

Drake
6 Sep, 2023, 16:26

Ah yes, content type is text rather than SVG 🧐

We definitely have to update Appwrite to support it

Nikky
6 Sep, 2023, 16:33

That would be awesome! Thanks! Do you have an expected date for that update? πŸ™‚

Nikky
6 Sep, 2023, 16:37

Also, quick question. Is there an endpoint to upload multiple files? Or do I need to loop and call createFile for each?

Drake
6 Sep, 2023, 17:43

loop

Drake
6 Sep, 2023, 17:44

not sure. make sure to πŸ‘πŸΌ the issue

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