diff --git a/src/Altinn.Broker.API/Controllers/LegacyFileController.cs b/src/Altinn.Broker.API/Controllers/LegacyFileController.cs index d1d4ba8a..37f37c6e 100644 --- a/src/Altinn.Broker.API/Controllers/LegacyFileController.cs +++ b/src/Altinn.Broker.API/Controllers/LegacyFileController.cs @@ -71,12 +71,16 @@ CancellationToken cancellationToken LogContextHelpers.EnrichLogsWithToken(legacyToken); logger.LogInformation("Legacy - Uploading file for file transfer {fileId}", fileTransferId.ToString()); - Request.EnableBuffering(); + if (Request.ContentLength is null) + { + return Problem("Content-length header is required"); + } var commandResult = await handler.Process(new UploadFileRequest() { FileTransferId = fileTransferId, Token = legacyToken, UploadStream = Request.Body, + ContentLength = Request.ContentLength.Value, IsLegacy = true }, HttpContext.User, cancellationToken); return commandResult.Match( diff --git a/tests/Altinn.Broker.Tests/LegacyFileControllerTests.cs b/tests/Altinn.Broker.Tests/LegacyFileControllerTests.cs index 003aca38..2349a550 100644 --- a/tests/Altinn.Broker.Tests/LegacyFileControllerTests.cs +++ b/tests/Altinn.Broker.Tests/LegacyFileControllerTests.cs @@ -64,6 +64,7 @@ public async Task InitializeAndUpload_Success() } var fileAfterUpload = await _legacyClient.GetFromJsonAsync($"broker/api/v1/legacy/file/{fileId}?onBehalfOfConsumer={onBehalfOfConsumer}", _responseSerializerOptions); Assert.NotNull(fileAfterUpload); + Assert.True(fileAfterUpload.FileSize == uploadedFileBytes.Length); Assert.Equal(LegacyFileStatusExt.Published, fileAfterUpload.FileStatus); // When running integration test this happens instantly as of now. }