Removed image upload functionality
This commit is contained in:
@@ -82,7 +82,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
@*<div class="form-group">
|
||||||
<label class="control-label col-md-6">@_item.PictureName</label>
|
<label class="control-label col-md-6">@_item.PictureName</label>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 esh-form-information">
|
<div class="col-md-6 esh-form-information">
|
||||||
@@ -96,7 +96,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<span class="col-md-12" style="color: red;"> @_badFileMessage </span>
|
<span class="col-md-12" style="color: red;"> @_badFileMessage </span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>*@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -85,7 +85,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
@*<div class="form-group">
|
||||||
<label class="control-label col-md-6">@_item.PictureName</label>
|
<label class="control-label col-md-6">@_item.PictureName</label>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 esh-form-information">
|
<div class="col-md-6 esh-form-information">
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<span class="col-md-12" style="color: red;"> @_badFileMessage </span>
|
<span class="col-md-12" style="color: red;"> @_badFileMessage </span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>*@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Microsoft.eShopWeb.Infrastructure.Services
|
namespace Microsoft.eShopWeb.Infrastructure.Services
|
||||||
{
|
{
|
||||||
|
// This class never gets called. Modify it based on your need.
|
||||||
|
|
||||||
public class WebFileSystem : IFileSystem
|
public class WebFileSystem : IFileSystem
|
||||||
{
|
{
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
private readonly string _url;
|
private readonly string _url;
|
||||||
public const string AUTH_KEY = "AuthKeyOfDoomThatMustBeAMinimumNumberOfBytes";
|
public const string AUTH_KEY = "<IMAGE_FILE_UPLOAD_API_KEY>";
|
||||||
|
|
||||||
public WebFileSystem(string url)
|
public WebFileSystem(string url)
|
||||||
{
|
{
|
||||||
@@ -50,13 +52,11 @@ namespace Microsoft.eShopWeb.Infrastructure.Services
|
|||||||
DataBase64 = Convert.ToBase64String(fileData),
|
DataBase64 = Convert.ToBase64String(fileData),
|
||||||
FileName = fileName
|
FileName = fileName
|
||||||
};
|
};
|
||||||
|
|
||||||
var content = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json");
|
var content = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
using var message = await _httpClient.PostAsync(_url, content, cancellationToken);
|
// TODO: Write the actual File image upload logic to web.
|
||||||
if (!message.IsSuccessStatusCode)
|
// Post this image binary content to an Image Upload API.
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,11 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
|||||||
{
|
{
|
||||||
private readonly IAsyncRepository<CatalogItem> _itemRepository;
|
private readonly IAsyncRepository<CatalogItem> _itemRepository;
|
||||||
private readonly IUriComposer _uriComposer;
|
private readonly IUriComposer _uriComposer;
|
||||||
private readonly IFileSystem _webFileSystem;
|
|
||||||
|
|
||||||
public Create(IAsyncRepository<CatalogItem> itemRepository, IUriComposer uriComposer, IFileSystem webFileSystem)
|
public Create(IAsyncRepository<CatalogItem> itemRepository, IUriComposer uriComposer)
|
||||||
{
|
{
|
||||||
_itemRepository = itemRepository;
|
_itemRepository = itemRepository;
|
||||||
_uriComposer = uriComposer;
|
_uriComposer = uriComposer;
|
||||||
_webFileSystem = webFileSystem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("api/catalog-items")]
|
[HttpPost("api/catalog-items")]
|
||||||
@@ -45,13 +43,16 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
|||||||
|
|
||||||
if (newItem.Id != 0)
|
if (newItem.Id != 0)
|
||||||
{
|
{
|
||||||
var picName = $"{newItem.Id}{Path.GetExtension(request.PictureName)}";
|
// At this point time, the Admin application uses the default catalog item image for any new product item.
|
||||||
if (await _webFileSystem.SavePicture(picName, request.PictureBase64, cancellationToken))
|
// But in the actual production scenario, you'll implement the image file upload mechanism in your application and set the image
|
||||||
{
|
// file the Uri accordingly. You can refer to fewlines of the boilerplate code are commented out and kept it in the following files.
|
||||||
|
// - BlazorAdmin project -> Create.razor and Edit.razor.
|
||||||
|
// - Infrastructure project -> Services/WebFileSystem.cs
|
||||||
|
|
||||||
|
var picName = "eCatalog-item-default.png";
|
||||||
newItem.UpdatePictureUri(picName);
|
newItem.UpdatePictureUri(picName);
|
||||||
await _itemRepository.UpdateAsync(newItem, cancellationToken);
|
await _itemRepository.UpdateAsync(newItem, cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var dto = new CatalogItemDto
|
var dto = new CatalogItemDto
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,14 +18,11 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
|||||||
{
|
{
|
||||||
private readonly IAsyncRepository<CatalogItem> _itemRepository;
|
private readonly IAsyncRepository<CatalogItem> _itemRepository;
|
||||||
private readonly IUriComposer _uriComposer;
|
private readonly IUriComposer _uriComposer;
|
||||||
private readonly IFileSystem _webFileSystem;
|
|
||||||
|
|
||||||
public Update(IAsyncRepository<CatalogItem> itemRepository, IUriComposer uriComposer, IFileSystem webFileSystem)
|
public Update(IAsyncRepository<CatalogItem> itemRepository, IUriComposer uriComposer)
|
||||||
{
|
{
|
||||||
_itemRepository = itemRepository;
|
_itemRepository = itemRepository;
|
||||||
_uriComposer = uriComposer;
|
_uriComposer = uriComposer;
|
||||||
_webFileSystem = webFileSystem;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("api/catalog-items")]
|
[HttpPut("api/catalog-items")]
|
||||||
@@ -45,19 +42,6 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
|||||||
existingItem.UpdateBrand(request.CatalogBrandId);
|
existingItem.UpdateBrand(request.CatalogBrandId);
|
||||||
existingItem.UpdateType(request.CatalogTypeId);
|
existingItem.UpdateType(request.CatalogTypeId);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(request.PictureBase64) && string.IsNullOrEmpty(request.PictureUri))
|
|
||||||
{
|
|
||||||
existingItem.UpdatePictureUri(string.Empty);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var picName = $"{existingItem.Id}{Path.GetExtension(request.PictureName)}";
|
|
||||||
if (await _webFileSystem.SavePicture($"{picName}", request.PictureBase64, cancellationToken))
|
|
||||||
{
|
|
||||||
existingItem.UpdatePictureUri(picName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await _itemRepository.UpdateAsync(existingItem, cancellationToken);
|
await _itemRepository.UpdateAsync(existingItem, cancellationToken);
|
||||||
|
|
||||||
var dto = new CatalogItemDto
|
var dto = new CatalogItemDto
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ namespace Microsoft.eShopWeb.PublicApi
|
|||||||
|
|
||||||
var baseUrlConfig = new BaseUrlConfiguration();
|
var baseUrlConfig = new BaseUrlConfiguration();
|
||||||
Configuration.Bind(BaseUrlConfiguration.CONFIG_NAME, baseUrlConfig);
|
Configuration.Bind(BaseUrlConfiguration.CONFIG_NAME, baseUrlConfig);
|
||||||
services.AddScoped<IFileSystem, WebFileSystem>(x => new WebFileSystem($"{baseUrlConfig.WebBase}File"));
|
|
||||||
|
|
||||||
services.AddMemoryCache();
|
services.AddMemoryCache();
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.eShopWeb.Web.ViewModels.File;
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BIN
src/Web/wwwroot/images/products/eCatalog-item-default.png
Normal file
BIN
src/Web/wwwroot/images/products/eCatalog-item-default.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
Reference in New Issue
Block a user