Corrupt file attachments
See original GitHub issueWe 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:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
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.
+1, yes.