coddingtonbear / obsidian-local-rest-api

Unlock your automation needs by interacting with your notes in Obsidian over a secure REST API.
MIT License
607 stars 56 forks source link

Cannot GET binary files #48

Closed geordielad closed 1 year ago

geordielad commented 1 year ago

If i GET a JPEG image file from my vault it seems to be getting corrupted. I am using python uplink module which is wrapping requests. I cannot save the file using the response.content, or recover the actual file from json content. Is the API assuming all files are markdown? Markdown files are working as expected. Thanks.

geordielad commented 1 year ago

I get the same problem using curl

curl -k -X 'GET' \ 'https://127.0.0.1:27124/vault/Files/Team%20of%20Teams.jpg' \ -H 'accept: image/jpeg' \ -H 'Authorization: Bearer d0...8a' > curl.jpg

coddingtonbear commented 1 year ago

I tried this out locally, and, yes -- you're totally right. There's a bug here!

When attempting to fetch a .png file out of my own vault and looking at the first few bytes, I see these:

\xef\xbf\xbdPNG

but, of course, the actual first few bytes for any PNG file are instead these:

\x89PNG

If you've got any experience with character encodings, you can probably tell what's going on here, but if you're not: what's happening is that something is attempting to interpret the bytes of the .png file as if it's text.

I've put together a fix in 255319913f5a9d2b5c36ce88a53713ea3a98c0d3 &'ll be putting together a release fixing it soon.