pramsey/pgsql-http

Get a svg image from http.get

Danilo-MSI opened this issue · 3 comments

Hello to you all! I hope everyone is doing fine!

Anyway, from the http.get function, I can get a JPEG, GIF and PNG image no problem. But, when it is a svg image all I can get is the xml code (if I can call it that). And not only that, but the "where" clause don't find any field with 'Content-Length' . For exemple, with this code:

WITH
http AS (
SELECT * FROM http_get('https://c2.scryfall.com/file/scryfall-symbols/card-symbols/T.svg')
),
headers AS (
SELECT (unnest(headers)).* FROM http
)
SELECT
http.content_type,
length(textsend(http.content)) AS length_binary,
textsend(http.content) AS image,
headers.value AS length_headers
FROM http, headers
WHERE field = 'Content-Length';

But even if I remove the "where" clause, I only get the "svg xmlns" code retuning in the "image" field ("textsend" function). Is there a way that I can get the bytea from the svg uri using, who knows, another function or some other way, maybe?

Thanks to you all!

Is it possible you are over-thinking this? The SVG is just text, so you don't need to do anything special to see it, just look at http.content. Works fine for me!

SELECT content FROM http_get('https://c2.scryfall.com/file/scryfall-symbols/card-symbols/T.svg');

Well, over-think it's my middle name...

What I wanted was to save the SVG image in a database, just like I did with JPEG, GIF and PNG in a bytea field. I'm doing a script for import the data from the Scryfall API and save it in a database in order to see the data without need the internet connection for that. If there isn't a way to do that with SVG, then I have to do a APP that reads the SVG content in order to show the image. I know that I can do that with I stay connected.

Anyway, thanks for the help! I'm going to do just like you suggest for now. And I'm sorry for the late update. I didn't see your message early.