Skip to content

Commit

Permalink
Disable upload before page save. Utl decode file name on upload.
Browse files Browse the repository at this point in the history
  • Loading branch information
NTDLS committed Dec 15, 2022
1 parent 72fc56b commit 98a6b9e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
13 changes: 9 additions & 4 deletions TightWiki/Controllers/FileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;
using TightWiki.Controllers;
using TightWiki.Shared.Library;
using TightWiki.Shared.Models.Data;
Expand Down Expand Up @@ -43,14 +44,16 @@ public IActionResult UploadDragDrop(string pageNavigation, List<IFormFile> poste
var fileSize = file.Length;
if (fileSize > 0)
{
var fileName = HttpUtility.UrlDecode(file.FileName);

PageFileRepository.UpsertPageFile(new PageFileAttachment()
{
Data = Utility.ConvertHttpFileToBytes(file),
CreatedDate = DateTime.UtcNow,
PageId = page.Id,
Name = file.FileName,
Name = fileName,
Size = fileSize,
ContentType = Utility.GetMimeType(file.FileName)
ContentType = Utility.GetMimeType(fileName)
});
return Content("Success");
}
Expand Down Expand Up @@ -83,14 +86,16 @@ public IActionResult UploadManual(string pageNavigation, IFormFile formFile)
var fileSize = file.Length;
if (fileSize > 0)
{
var fileName = HttpUtility.UrlDecode(file.FileName);

PageFileRepository.UpsertPageFile(new PageFileAttachment()
{
Data = Utility.ConvertHttpFileToBytes(file),
CreatedDate = DateTime.UtcNow,
PageId = page.Id,
Name = file.FileName,
Name = fileName,
Size = fileSize,
ContentType = Utility.GetMimeType(file.FileName)
ContentType = Utility.GetMimeType(fileName)
});

return Content("Success");
Expand Down
26 changes: 17 additions & 9 deletions TightWiki/Views/Page/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,24 @@
<div class="card">
<div class="card-header"><h3>Attachments</h3></div>
<div class="card-body">
<div id="dropSection" class="dropSection">
<br />Attach files by dropping them here or by manually selcting them below:<br /><br />
<div id="manualUpload">
<form id="manualUpload" action="/upload" enctype="multipart/form-data" method="post"><input type="file" name="BinaryData"><input type="submit" value="Upload"></form>
</div>
@if (Model?.Id > 0 && @ViewBag.Config.Context?.CanCreate == true)
{

</div>
<div id="uploadedFiles">
</div>
<input type="button" id="btnUpload" value="Upload" />
<div id="dropSection" class="dropSection">
<br />Attach files by dropping them here or by manually selcting them below:<br /><br />
<div id="manualUpload">
<form id="manualUpload" action="/upload" enctype="multipart/form-data" method="post"><input type="file" name="BinaryData"><input type="submit" value="Upload"></form>
</div>

</div>
<div id="uploadedFiles">
</div>
<input type="button" id="btnUpload" value="Upload" />
}
else
{
<div>Save the page before uploading files.</div>
}
</div>
</div>
</div>

0 comments on commit 98a6b9e

Please sign in to comment.