Skip to content

Commit

Permalink
Legacy file uploads also need content length (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceredron authored Nov 28, 2024
1 parent e8ffeee commit e3489c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Altinn.Broker.API/Controllers/LegacyFileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions tests/Altinn.Broker.Tests/LegacyFileControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public async Task InitializeAndUpload_Success()
}
var fileAfterUpload = await _legacyClient.GetFromJsonAsync<LegacyFileOverviewExt>($"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.
}

Expand Down

0 comments on commit e3489c8

Please sign in to comment.