Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Exported server routes returning binary files get corrupted #1103

Closed
aloker opened this issue Feb 28, 2020 · 4 comments · Fixed by #1398
Closed

Exported server routes returning binary files get corrupted #1103

aloker opened this issue Feb 28, 2020 · 4 comments · Fixed by #1398

Comments

@aloker
Copy link
Contributor

aloker commented Feb 28, 2020

Describe the bug
When a route points to a server route that emits a binary file (pdf, image etc.) and the site is exported, the files on disk get corrupted because export only supports text results from server routes.

To Reproduce

  • Create a server route that returns a binary file (image, PDF)
  • Link to the server route inside a Svelte component
  • Export the site
  • Find the exported file of the server route on disk

Result: the file is corrupt and cannot be opened.

Expected behavior
The result of server routes emitting binary data should be properly stored on disk when exporting.

Information about your Sapper Installation:

  • Sapper master branch (v0.27.10)
  • Exported site
  • Checked with rollup, but should be same for webpack

Severity
Blocking my attempt to load all data including binary assets (documents, images) from a headless CMS.

@swyxio
Copy link

swyxio commented Mar 3, 2020

this seems pretty serious. can you move the work to clientside? or must it be in a server route?

@aloker
Copy link
Contributor Author

aloker commented Mar 8, 2020

In the API routes, I pull in images from a CMS and transform them using Sharp, so yes, it has to be server side.

@jrob-io
Copy link

jrob-io commented Mar 24, 2020

I ran into this issue, too. I realized that this.fetch uses proc.send to send the response body in a JSON object to the export CLI.

body: Buffer.concat(chunks).toString()

JSON is utf8 which results in binary data being lost, so I base64 encoded it before and after the message was sent. After this, binary files started appearing normally in my __sapper__/export folder.

@dennybritz
Copy link

Is there any news on this getting fixed? It seems like I cannot export binary files and this is blocking me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants