修改BUG:Mac系统下更改头像失败 closed #ITBTJ

#Issue
https://gitee.com/LongbowEnterprise/BootstrapAdmin/issues/ITBTJ
This commit is contained in:
Argo Zhang 2019-03-09 20:04:04 +08:00
parent a8a6e9df5c
commit c6dd02df86
3 changed files with 8 additions and 6 deletions

View File

@ -1,5 +1,6 @@
using Bootstrap.Admin.Models; using Bootstrap.Admin.Models;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
@ -87,8 +88,9 @@ namespace Bootstrap.Admin.Controllers
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="host"></param>
/// <returns></returns> /// <returns></returns>
public ActionResult Profiles() => View(new ProfilesModel(this)); public ActionResult Profiles([FromServices]IHostingEnvironment host) => View(new ProfilesModel(this, host));
/// <summary> /// <summary>
/// ///

View File

@ -36,7 +36,7 @@ namespace Bootstrap.Admin.Controllers.Api
var webSiteUrl = DictHelper.RetrieveIconFolderPath(); var webSiteUrl = DictHelper.RetrieveIconFolderPath();
fileName = string.Format("{0}{1}", userName, Path.GetExtension(uploadFile.FileName)); fileName = string.Format("{0}{1}", userName, Path.GetExtension(uploadFile.FileName));
var fileUrl = string.Format("{0}{1}", webSiteUrl, fileName); var fileUrl = string.Format("{0}{1}", webSiteUrl, fileName);
var filePath = Path.Combine(env.WebRootPath, webSiteUrl.Replace("~", string.Empty).Replace("/", "\\").TrimStart('\\') + fileName); var filePath = Path.Combine(env.WebRootPath, webSiteUrl.Replace("~", string.Empty).Replace('/', Path.DirectorySeparatorChar).TrimStart(Path.DirectorySeparatorChar) + fileName);
var fileFolder = Path.GetDirectoryName(filePath); var fileFolder = Path.GetDirectoryName(filePath);
fileSize = uploadFile.Length; fileSize = uploadFile.Length;
if (!Directory.Exists(fileFolder)) Directory.CreateDirectory(fileFolder); if (!Directory.Exists(fileFolder)) Directory.CreateDirectory(fileFolder);
@ -53,7 +53,7 @@ namespace Bootstrap.Admin.Controllers.Api
fileName = files["key"]; fileName = files["key"];
if (!fileName.Equals("default.jpg")) if (!fileName.Equals("default.jpg"))
{ {
fileName = Path.Combine(env.WebRootPath, $"images\\uploader\\{fileName}"); fileName = Path.Combine(env.WebRootPath, $"images{Path.DirectorySeparatorChar}uploader{Path.DirectorySeparatorChar}{fileName}");
try try
{ {
if (System.IO.File.Exists(fileName)) System.IO.File.Delete(fileName); if (System.IO.File.Exists(fileName)) System.IO.File.Delete(fileName);

View File

@ -22,13 +22,13 @@ namespace Bootstrap.Admin.Models
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="host"></param>
/// <param name="controller"></param> /// <param name="controller"></param>
public ProfilesModel(ControllerBase controller) : base(controller) public ProfilesModel(ControllerBase controller, IHostingEnvironment host) : base(controller)
{ {
var host = controller.HttpContext.RequestServices.GetService(typeof(IHostingEnvironment)) as IHostingEnvironment;
if (host != null) if (host != null)
{ {
var fileName = Path.Combine(host.WebRootPath, Icon.TrimStart('~', '/').Replace('/', '\\')); var fileName = Path.Combine(host.WebRootPath, Icon.TrimStart('~', '/').Replace('/', Path.DirectorySeparatorChar));
if (File.Exists(fileName)) if (File.Exists(fileName))
{ {
Size = new FileInfo(fileName).Length; Size = new FileInfo(fileName).Length;