From 28df3f4ec172581ea63a79fb2984afa68c5281bc Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 29 May 2026 14:09:31 +0200 Subject: [PATCH] Refactor document handling and improve file response Refactored the handling of `senderDoc.ByteData` by replacing the ternary operator with an explicit `if` statement for better readability. Added a `Content-Disposition` header to ensure the file is displayed inline with a proper filename. Updated the MIME type of the file response from `application/octet-stream` to `application/pdf` to reflect the expected content type. --- .../Controllers/DocumentController.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/EnvelopeGenerator.API/Controllers/DocumentController.cs b/EnvelopeGenerator.API/Controllers/DocumentController.cs index 41d43fc2..37d3a0a3 100644 --- a/EnvelopeGenerator.API/Controllers/DocumentController.cs +++ b/EnvelopeGenerator.API/Controllers/DocumentController.cs @@ -87,8 +87,10 @@ public class DocumentController(IMediator mediator, IAuthorizationService authSe var senderDoc = await mediator.Send(new ReadDocumentQuery() { EnvelopeId = envelopeId }, cancel); - return senderDoc.ByteData is byte[] senderDocByte - ? File(senderDocByte, "application/octet-stream") - : NotFound("Document is empty."); + if (senderDoc.ByteData is not byte[] senderDocByte) + return NotFound("Document is empty."); + + Response.Headers.ContentDisposition = $"inline; filename=\"{envelopeKey}.pdf\""; + return File(senderDocByte, "application/pdf"); } -} \ No newline at end of file +}