Image added (#434)
* Image added * ImageMaximumBytes * FileController remove Authorized * ApplicationCore.Constants.AuthorizationConstants.AUTH_KEY * SavePicture in the interface. * IFileSystem in Core * WebFileSystem in Infrastructure * PictureUri removed from UpdateCatalogItemRequest * Modal scroll fix
This commit is contained in:
38
src/Web/Controllers/FileController.cs
Normal file
38
src/Web/Controllers/FileController.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopWeb.Web.ViewModels.File;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
public class FileController : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public IActionResult Upload(FileViewModel fileViewModel)
|
||||
{
|
||||
if (!Request.Headers.ContainsKey("auth-key") || Request.Headers["auth-key"].ToString() != ApplicationCore.Constants.AuthorizationConstants.AUTH_KEY)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
if(fileViewModel == null || string.IsNullOrEmpty(fileViewModel.DataBase64)) return BadRequest();
|
||||
|
||||
var fileData = Convert.FromBase64String(fileViewModel.DataBase64);
|
||||
if (fileData.Length <= 0) return BadRequest();
|
||||
|
||||
var fullPath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot/images/products", fileViewModel.FileName);
|
||||
if (System.IO.File.Exists(fullPath))
|
||||
{
|
||||
System.IO.File.Delete(fullPath);
|
||||
}
|
||||
System.IO.File.WriteAllBytes(fullPath, fileData);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@
|
||||
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" />
|
||||
</environment>
|
||||
<link href="css/admin.css" rel="stylesheet" />
|
||||
|
||||
<script src="_content/BlazorInputFile/inputfile.js"></script>
|
||||
<script>
|
||||
|
||||
window.getCookie = (cname) => {
|
||||
@@ -55,6 +55,14 @@
|
||||
window.location = path;
|
||||
};
|
||||
|
||||
window.hideBodyOverflow = () => {
|
||||
document.body.classList.add("body-no-overflow");
|
||||
};
|
||||
|
||||
window.showBodyOverflow = () => {
|
||||
document.body.classList.remove("body-no-overflow");
|
||||
};
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
14
src/Web/ViewModels/File/FileViewModel.cs
Normal file
14
src/Web/ViewModels/File/FileViewModel.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.ViewModels.File
|
||||
{
|
||||
public class FileViewModel
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string DataBase64 { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user