Skip to content

Commit 1394d11

Browse files
authored
Merge pull request #2449 from TechnologyEnhancedLearning/Develop/Fixes/TD-2286-FixTestingFails
TD-2286 Addresses issues with attaching more than 20 MB in separate uploads
2 parents d99fd62 + a6f57e9 commit 1394d11

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

DigitalLearningSolutions.Data/Models/Support/RequestAttachment.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class RequestAttachment
1010
{
1111
public string? Id { get; set; }
1212
public string? FileName { get; set; }
13+
public double? SizeMb { get; set; }
1314
public string? OriginalFileName { get; set; }
1415
public string? FullFileName { get; set; }
1516
public byte[] Content { get; set; }

DigitalLearningSolutions.Web/Controllers/Support/RequestSupportTicketController.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ public IActionResult SetAttachment(DlsSubApplication dlsSubApplication, RequestA
170170
MultiPageFormDataFeature.AddCustomWebForm("RequestSupportTicketCWF"),
171171
TempData
172172
).GetAwaiter().GetResult(); ;
173-
173+
requestAttachmentmodel.RequestAttachment = data.RequestAttachment;
174174
if (requestAttachmentmodel.ImageFiles == null)
175175
{
176-
requestAttachmentmodel.RequestAttachment = data.RequestAttachment;
176+
//requestAttachmentmodel.RequestAttachment = data.RequestAttachment;
177177
ModelState.AddModelError("ImageFiles", "Please select at least one image");
178178
return View("RequestAttachment", requestAttachmentmodel);
179179
}
@@ -184,13 +184,13 @@ public IActionResult SetAttachment(DlsSubApplication dlsSubApplication, RequestA
184184
(bool? fileExtension, bool? fileSize) = validateUploadedImages(requestAttachmentmodel);
185185
if (fileExtension == true)
186186
{
187-
requestAttachmentmodel.RequestAttachment = data.RequestAttachment;
187+
//requestAttachmentmodel.RequestAttachment = data.RequestAttachment;
188188
ModelState.AddModelError("FileExtensionError", "File must be in valid image formats jpg, jpeg, png, bmp or mp4 video format");
189189
return View("RequestAttachment", requestAttachmentmodel);
190190
}
191191
if (fileSize == true)
192192
{
193-
requestAttachmentmodel.RequestAttachment = data.RequestAttachment;
193+
//requestAttachmentmodel.RequestAttachment = data.RequestAttachment;
194194
ModelState.AddModelError("FileSizeError", "Maximum allowed file size is 20MB");
195195
return View("RequestAttachment", requestAttachmentmodel);
196196
}
@@ -202,7 +202,8 @@ public IActionResult SetAttachment(DlsSubApplication dlsSubApplication, RequestA
202202
{
203203
OriginalFileName = item.FileName,
204204
FileName = fileName,
205-
FullFileName = uploadDir + fileName
205+
FullFileName = uploadDir + fileName,
206+
SizeMb = Convert.ToDouble(item.Length.ToSize(FileSizeCalc.SizeUnits.MB))
206207
};
207208
RequestAttachmentList.Add(RequestAttachment);
208209
}
@@ -370,6 +371,13 @@ private string UploadFile(IFormFile file)
370371
private (bool, bool) validateUploadedImages(RequestAttachmentViewModel requestAttachmentmodel)
371372
{
372373
var totalFileSize = 0.00;
374+
if (requestAttachmentmodel.RequestAttachment != null)
375+
{
376+
foreach (var item in requestAttachmentmodel.RequestAttachment)
377+
{
378+
totalFileSize = totalFileSize + item.SizeMb??0;
379+
}
380+
}
373381
foreach (var item in requestAttachmentmodel.ImageFiles)
374382
{
375383
var extension = Path.GetExtension(item.FileName);
@@ -380,10 +388,11 @@ private string UploadFile(IFormFile file)
380388
}
381389
var fileSize = Convert.ToDouble(item.Length.ToSize(FileSizeCalc.SizeUnits.MB));
382390
totalFileSize = totalFileSize + fileSize;
383-
if (fileSize > requestAttachmentmodel.SizeLimit || totalFileSize > requestAttachmentmodel.SizeLimit)
384-
{
385-
requestAttachmentmodel.FileSizeFlag = true;
386-
}
391+
392+
}
393+
if (totalFileSize > requestAttachmentmodel.SizeLimit)
394+
{
395+
requestAttachmentmodel.FileSizeFlag = true;
387396
}
388397
return (requestAttachmentmodel.FileExtensionFlag ?? false, requestAttachmentmodel.FileSizeFlag ?? false);
389398
}

DigitalLearningSolutions.Web/Views/Support/RequestSupportTicket/RequestAttachment.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</legend>
3535
<div class="nhsuk-form-group">
3636
<label class="nhsuk-label" for="ImageFiles">
37-
If you have any screenshots that help illustrate your request, attach them here. The maximum total file size for uploaded files is 20MB.
37+
If you have any screenshots that help illustrate your request, attach them here. The maximum total file size for uploaded files is 20 MB.
3838
</label>
3939
@if (!ViewData.ModelState.IsValid)
4040
{
@@ -60,7 +60,7 @@
6060
<div class="nhsuk-summary-list__row">
6161

6262
<dd class="nhsuk-summary-list__value">
63-
@a.OriginalFileName
63+
@a.OriginalFileName (@a.SizeMb.ToString() MB)
6464
</dd>
6565
<dd class="nhsuk-summary-list__actions">
6666
<a asp-action="DeleteImage" asp-all-route-data="@cancelLinkData" asp-route-imageName="@a.FileName" asp-route-imageId="@a.Id">

0 commit comments

Comments
 (0)