question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Corrupt file attachments

See original GitHub issue

We encountered an issue where a file download triggered via the Content-Disposition header will result in a link to download the file, but the file will be corrupt. A similiar issue is also documented in following swagger-ui issue:

https://github.com/swagger-api/swagger-ui/issues/4638

In our case we want to download a tar-file. So the content-type of the response is application/gzip. We want to add the download-endpoint to the swagger-documentation but if we do that the downloaded file is corrupt.

In the https://github.com/swagger-api/swagger-ui/issues/4638 Issue the solution is to upgrade to Swagger UI 3. Is there a workaround in fastify-swagger?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Stezidocommented, Nov 19, 2018

Isn’t swagger ui same as the dependency "swagger-ui-dist": "3.19.5" or am I missing something ?

You are right fastify-swagger is already using swagger ui 3. This issue is caused by ajv the validator of fastify. For someone who is running in a similar issue i summed up my story.

The Swagger docu describes a “response that returns a file” My response schema looks like this for a gzip-file:

response: {
       200: {
          type : "string",
          format: "binary",
      },
 },

The ajv validator offers following types: number, integer, string, boolean, array, object or null and following formats for type “string”: date, date-time, uri, email, hostname, ipv4, ipv6, regex

So there is a type “string” but no format “binary”!

Only defining the type as “string” or “object” doesn’t make it because the file downloaded will be corrupt

add a byte/binary format to ajv via addFormat would be my guess how to fix it, but I couldn’t add a new format because fast-json-stringify uses it’s own instance of ajv internally. This issue describe a problem of fast-json-stringify I also ran into. The issue was solved in version 1.8.0. of fast-json-stringify by setting the option unknownFormats: “ignore” to the intern ajv instance. So updating fastify made it for me.

0reactions
mcollinacommented, Nov 19, 2018

+1, yes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"The file is corrupted and cannot be opened" error message ...
Describes a problem in which you cannot open an Excel, Word or PowerPoint email attachment. You receive a “This file is corrupt and...
Read more >
Solved: How to Fix a Corrupt File and Cannot Be Opened
Here's how to fix the corrupted file message in two steps. ... open Microsoft Excel email attachment due to a 'Protected View' setting...
Read more >
Outlook 2016 Corrupt Attachment - Tech Info & Solutions
Go to File, Options, Add-ins · At the bottom click Go, beside COM Add-ins · Unclick the checkmark beside Adobe Send and Track...
Read more >
How to avoid corrupt email attachment in Power Automate
Corrupt attachment from an email is one of the most common problems in Power Automate. It doesn't matter if you need to download...
Read more >
How Can I Fix "Unable to Open Outlook Attachment" Issue?
If the Outlook data file (PST) is corrupt, it could be the reason why you can't open attachments. You can repair the file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found