Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFODEV-713: Hotfix for file sizes #241

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Application/Common/Versioning/Documents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class Documents
{
public static class Consent
{
public const double MaximumSizeInMegabytes = 5;
public const double MaximumSizeInMegabytes = 1;

public static IReadOnlyList<string> Versions { get; set; } =
[
Expand All @@ -14,7 +14,7 @@ public static class Consent

public static class RightToWork
{
public const double MaximumSizeInMegabytes = 5;
public const double MaximumSizeInMegabytes = 1;
}

}
10 changes: 6 additions & 4 deletions src/Application/Features/Participants/Commands/AddConsent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public async Task<Result<string>> Handle(Command request, CancellationToken canc
$"Consent form for {request.ParticipantId}",
DocumentType.PDF);


await using var stream = request.Document.OpenReadStream();
long maxSizeBytes = Convert.ToInt64(ByteSize.FromMegabytes(Infrastructure.Constants.Documents.Consent.MaximumSizeInMegabytes).Bytes);
await using var stream = request.Document.OpenReadStream(maxSizeBytes);
using var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream, cancellationToken);

Expand Down Expand Up @@ -87,7 +87,7 @@ public Validator(IUnitOfWork unitOfWork)

RuleFor(v => v.Document)
.NotNull()
.WithMessage("You must upload a Right to Work document")
.WithMessage("You must upload a Consent document")
.Must(file => NotExceedMaximumFileSize(file, Infrastructure.Constants.Documents.Consent.MaximumSizeInMegabytes))
.WithMessage($"File size exceeds the maxmimum allowed size of {Infrastructure.Constants.Documents.Consent.MaximumSizeInMegabytes} megabytes")
.MustAsync(BePdfFile)
Expand Down Expand Up @@ -123,8 +123,10 @@ private async Task<bool> BePdfFile(IBrowserFile? file, CancellationToken cancell
if (file.ContentType != "application/pdf")
return false;

long maxSizeBytes = Convert.ToInt64(ByteSize.FromMegabytes(Infrastructure.Constants.Documents.Consent.MaximumSizeInMegabytes).Bytes);

// Check file signature (magic numbers)
using (var stream = file.OpenReadStream())
using (var stream = file.OpenReadStream(maxSizeBytes))
{
byte[] buffer = new byte[4];
await stream.ReadAsync(buffer, 0, 4, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public async Task<Result<string>> Handle(Command request, CancellationToken canc
$"Right to work evidence for {request.ParticipantId}",
DocumentType.PDF);

await using var stream = request.Document.OpenReadStream();
long maxSizeBytes = Convert.ToInt64(ByteSize.FromMegabytes(Infrastructure.Constants.Documents.Consent.MaximumSizeInMegabytes).Bytes);
await using var stream = request.Document.OpenReadStream(maxSizeBytes);
using var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream, cancellationToken);

Expand Down Expand Up @@ -133,8 +134,10 @@ private async Task<bool> BePdfFile(IBrowserFile? file, CancellationToken cancell
if (file.ContentType != "application/pdf")
return false;

long maxSizeBytes = Convert.ToInt64(ByteSize.FromMegabytes(Infrastructure.Constants.Documents.Consent.MaximumSizeInMegabytes).Bytes);

// Check file signature (magic numbers)
using (var stream = file.OpenReadStream())
using (var stream = file.OpenReadStream(maxSizeBytes))
{
byte[] buffer = new byte[4];
await stream.ReadAsync(buffer, 0, 4, cancellationToken);
Expand Down
Loading