Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Fix - upload file in ContactAttribute / CheckoutAttribute
supporte076eb5fa5cb
diff --git a/src/Core/Grand.Domain/Media/Download.cs b/src/Core/Grand.Domain/Media/Download.csindex 2fe65fb49..25aa57782 100644--- a/src/Core/Grand.Domain/Media/Download.cs+++ b/src/Core/Grand.Domain/Media/Download.cs@@ -5,6 +5,11 @@ namespace Grand.Domain.Media/// </summary>public partial class Download : BaseEntity{+ /// <summary>+ /// Gets or sets a customer identifier+ /// </summary>+ public string CustomerId { get; set; }+/// <summary>/// Gets or sets a GUID/// </summary>diff --git a/src/Web/Grand.Web/Controllers/ContactController.cs b/src/Web/Grand.Web/Controllers/ContactController.csindex 25e10d4cc..442235769 100644--- a/src/Web/Grand.Web/Controllers/ContactController.cs+++ b/src/Web/Grand.Web/Controllers/ContactController.cs@@ -121,7 +121,6 @@ public class ContactController : BasePublicController[HttpPost][DenySystemAccount]public virtual async Task<IActionResult> UploadFileContactAttribute(string attributeId,- IFormFile uploadedFile,[FromServices] IDownloadService downloadService,[FromServices] IContactAttributeService contactAttributeService){@@ -134,7 +133,9 @@ public class ContactController : BasePublicController});}- if (uploadedFile == null)+ var form = await HttpContext.Request.ReadFormAsync();+ var httpPostedFile = form.Files.FirstOrDefault();+ if (httpPostedFile == null){return Json(new {success = false,@@ -143,14 +144,13 @@ public class ContactController : BasePublicController});}- var fileBinary = uploadedFile.GetDownloadBits();+ var fileBinary = httpPostedFile.GetDownloadBits();- var fileName = uploadedFile.FileName;+ var fileName = httpPostedFile.FileName;- //remove path (passed in IE)fileName = Path.GetFileName(fileName);- var contentType = uploadedFile.ContentType;+ var contentType = httpPostedFile.ContentType;var fileExtension = Path.GetExtension(fileName);if (!string.IsNullOrEmpty(fileExtension))@@ -190,11 +190,11 @@ public class ContactController : BasePublicControllervar download = new Download {DownloadGuid = Guid.NewGuid(),+ CustomerId = _workContext.CurrentCustomer.Id,UseDownloadUrl = false,DownloadUrl = "",DownloadBinary = fileBinary,ContentType = contentType,- //we store filename without extension for downloadsFilename = Path.GetFileNameWithoutExtension(fileName),Extension = fileExtension,IsNew = truediff --git a/src/Web/Grand.Web/Controllers/DownloadController.cs b/src/Web/Grand.Web/Controllers/DownloadController.csindex a3694e476..37350a38b 100644--- a/src/Web/Grand.Web/Controllers/DownloadController.cs+++ b/src/Web/Grand.Web/Controllers/DownloadController.cs@@ -208,6 +208,9 @@ namespace Grand.Web.Controllersif (download == null)return Content("Download is not available any more.");+ if (_workContext.CurrentCustomer == null || download.CustomerId != _workContext.CurrentCustomer.Id)+ return Challenge();+if (download.UseDownloadUrl)return new RedirectResult(download.DownloadUrl);diff --git a/src/Web/Grand.Web/Controllers/ProductController.cs b/src/Web/Grand.Web/Controllers/ProductController.csindex f0a56f536..41821359c 100644--- a/src/Web/Grand.Web/Controllers/ProductController.cs+++ b/src/Web/Grand.Web/Controllers/ProductController.cs@@ -230,13 +230,7 @@ namespace Grand.Web.Controllers});}var fileBinary = httpPostedFile.GetDownloadBits();-- const string qqFileNameParameter = "qqfilename";var fileName = httpPostedFile.FileName;- if (string.IsNullOrEmpty(fileName) && form.ContainsKey(qqFileNameParameter))- fileName = form[qqFileNameParameter].ToString();- //remove path (passed in IE)- fileName = Path.GetFileName(fileName);var contentType = httpPostedFile.ContentType;@@ -278,11 +272,11 @@ namespace Grand.Web.Controllersvar download = new Download {DownloadGuid = Guid.NewGuid(),+ CustomerId = _workContext.CurrentCustomer.Id,UseDownloadUrl = false,DownloadUrl = "",DownloadBinary = fileBinary,ContentType = contentType,- //we store filename without extension for downloadsFilename = Path.GetFileNameWithoutExtension(fileName),Extension = fileExtension,IsNew = truediff --git a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs b/src/Web/Grand.Web/Controllers/ShoppingCartController.csindex 8a691995f..ac9d1b0af 100644--- a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs+++ b/src/Web/Grand.Web/Controllers/ShoppingCartController.cs@@ -172,7 +172,6 @@ namespace Grand.Web.Controllers[DenySystemAccount][HttpPost]public virtual async Task<IActionResult> UploadFileCheckoutAttribute(string attributeId,- IFormFile uploadedFile,[FromServices] IDownloadService downloadService){var attribute = await _checkoutAttributeService.GetCheckoutAttributeById(attributeId);@@ -183,7 +182,9 @@ namespace Grand.Web.ControllersdownloadGuid = Guid.Empty});}- if (uploadedFile == null)+ var form = await HttpContext.Request.ReadFormAsync();+ var httpPostedFile = form.Files.FirstOrDefault();+ if (httpPostedFile == null){return Json(new {success = false,@@ -192,13 +193,12 @@ namespace Grand.Web.Controllers});}- var fileBinary = uploadedFile.GetDownloadBits();- var fileName = uploadedFile.FileName;+ var fileBinary = httpPostedFile.GetDownloadBits();+ var fileName = httpPostedFile.FileName;- //remove path (passed in IE)fileName = Path.GetFileName(fileName);- var contentType = uploadedFile.ContentType;+ var contentType = httpPostedFile.ContentType;var fileExtension = Path.GetExtension(fileName);if (!string.IsNullOrEmpty(fileExtension))@@ -238,11 +238,11 @@ namespace Grand.Web.Controllersvar download = new Download {DownloadGuid = Guid.NewGuid(),+ CustomerId = _workContext.CurrentCustomer.Id,UseDownloadUrl = false,DownloadUrl = "",DownloadBinary = fileBinary,ContentType = contentType,- //we store filename without extension for downloadsFilename = Path.GetFileNameWithoutExtension(fileName),Extension = fileExtension,IsNew = true