-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Can't return image from non-html route #4545
Description
What version of astro are you using?
1.1.1
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm
What operating system are you using?
Linux
Describe the Bug
I'm trying to return a PNG buffer from a non-html route in SSG mode. Due to this line of code that writes the file using utf-8 encoding my binary buffer is getting mangled as it is written to disk.
Because SSG mode non-html routes cannot return a response, only a string body, there is no ability to specify an encoding or other data about the file being returned. Therefore I don't think it is currently possible to return an image from a non-html route.
FWIW Rodney has posted a tutorial on using pdf.js and returning a PDF from a non-html route, and it works. The pdf buffer is binary encoded but it doesn't seem to get mangled when writing it out with utf-8 encoding. I don't understand why.
NOTE: The stackblitz link below doesn't build because unpaid accounts can't produce binary files. The code is correct though, I think.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-thahaq?file=src%2Fpages%2Ftest.jpg.ts&on=stackblitz
Participation
- I am willing to submit a pull request for this issue.