{"id":304032,"date":"2020-05-21T21:00:38","date_gmt":"2020-05-21T21:00:38","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=304032"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=304032","title":{"rendered":"\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0432 .NET Core"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/503028\/\">\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0441\u0432\u043e\u0451\u043c \u043e\u043f\u044b\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0432 .NET Core \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0438\u0445 \u0440\u0435\u0441\u0430\u0439\u0437\u043e\u043c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u0414\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/SixLabors\/ImageSharp\" rel=\"nofollow\">ImageSharp<\/a> \u043e\u0442 Six Labors. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438, \u043d\u043e \u0442.\u043a. \u044f \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u0438 \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. \u041d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u043e\u043d\u0438 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 \u0440\u0435\u043b\u0438\u0437-\u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u0430, \u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e \u0443\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. <br \/>  \u0417\u0430\u0434\u0430\u0447\u0435\u0439 \u0431\u044b\u043b\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u0444\u0440\u043e\u043d\u0442\u0430, \u043e\u0431\u0440\u0435\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u0440\u043e\u043d \u0438 \u0440\u0435\u0441\u0430\u0439\u0437\u0438\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0435 \u0441\u044a\u0435\u0434\u0430\u043b\u043e \u043c\u043d\u043e\u0433\u043e \u0434\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430, \u0432\u0435\u0434\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0433\u0430\u0431\u0430\u0439\u0442 \u0432 \u043e\u0431\u043b\u0430\u043a\u0435 \u2014 \u044d\u0442\u043e \u0434\u0435\u043d\u044c\u0433\u0438. <br \/>  <a name=\"habracut\"><\/a><br \/>  \u041d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435 \u0431\u044b\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d Angular-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0431\u043e\u0440\u0430 \u0444\u0430\u0439\u043b\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u043d\u0430 API \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f. API \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0443\u0442\u044c \u043a \u0443\u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u043c\u0443 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0442\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0411\u0414. \u0422.\u043a. \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0435 \u043e Angular, \u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0438 \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u0441\u0440\u0430\u0437\u0443 \u043a API \u043c\u0435\u0442\u043e\u0434\u0443.<\/p>\n<pre><code class=\"cpp\">[HttpPost] [Route(&quot;upload\/box&quot;)] public IActionResult UploadBoxImage(IFormFile file) {     return UploadImage(file, ImageType.Box); }  [HttpPost] [Route(&quot;upload\/logo&quot;)] public IActionResult UploadLogoImage(IFormFile file) {     return UploadImage(file, ImageType.Logo); }  private IActionResult UploadImage(IFormFile file, ImageType type) {     if (file.Length == 0)         return BadRequest(new ApiResponse(ErrorCodes.EmptyFile, Strings.EmptyFile));      try     {         var filePath = _imageService.SaveImage(file, type);         return Ok(new ApiResponse&lt;string&gt;(filePath));     }     catch (ImageProcessingException ex)     {         var response = new ApiResponse(ErrorCodes.ImageProcessing, ex.Message);         return BadRequest(response);     }     catch (Exception ex)     {         var response = new ApiResponse(ErrorCodes.Unknown, ex.Message);         return BadRequest(response);     } } <\/code><\/pre>\n<p>  \u0410 \u0435\u0441\u043b\u0438 \u0431\u044b\u0442\u044c \u0442\u043e\u0447\u043d\u0435\u0435, \u0442\u043e \u043a \u0434\u0432\u0443\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c. \u041c\u043e\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0431\u044b\u043b\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445. \u0422\u0438\u043f\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0432 Enum <code><b>ImageType<\/b><\/code>. \u0410 \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code><b>IImageProfile<\/b><\/code> \u0438 \u0434\u0432\u0435 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0433\u0434\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"cpp\">public interface IImageProfile {     ImageType ImageType { get; }      string Folder { get; }      int Width { get; }      int Height { get; }      int MaxSizeBytes { get; }      IEnumerable&lt;string&gt; AllowedExtensions { get; } } <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"cpp\">public class BoxImageProfile : IImageProfile {     private const int mb = 1048576;      public BoxImageProfile()     {         AllowedExtensions = new List&lt;string&gt; { &quot;.jpg&quot;, &quot;.jpeg&quot;, &quot;.png&quot;, &quot;.gif&quot; };     }      public ImageType ImageType =&gt; ImageType.Box;      public string Folder =&gt; &quot;boxes&quot;;      public int Width =&gt; 500;      public int Height =&gt; 500;      public int MaxSizeBytes =&gt; 10 * mb;      public IEnumerable&lt;string&gt; AllowedExtensions { get; } } <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"cpp\">public class LogoImageProfile : IImageProfile {     private const int mb = 1048576;      public LogoImageProfile()     {         AllowedExtensions = new List&lt;string&gt; { &quot;.jpg&quot;, &quot;.jpeg&quot;, &quot;.png&quot;, &quot;.gif&quot; };     }      public ImageType ImageType =&gt; ImageType.Logo;      public string Folder =&gt; &quot;logos&quot;;      public int Width =&gt; 300;      public int Height =&gt; 300;      public int MaxSizeBytes =&gt; 5 * mb;      public IEnumerable&lt;string&gt; AllowedExtensions { get; } } <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u044d\u0442\u0438 \u043f\u0440\u043e\u0444\u0430\u0439\u043b\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u044f \u0431\u0443\u0434\u0443 \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0442\u044c \u0432 \u043c\u0435\u0442\u043e\u0434 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0438\u0445 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435. <\/p>\n<pre><code class=\"cpp\">... services.AddTransient&lt;IImageProfile, BoxImageProfile&gt;(); services.AddTransient&lt;IImageProfile, LogoImageProfile&gt;(); ... <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u043b\u0438 \u0441\u0435\u0440\u0432\u0438\u0441 \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e <code><b>IImageProfile<\/b><\/code><\/p>\n<pre><code class=\"cpp\">... private readonly IEnumerable&lt;IImageProfile&gt; _imageProfiles;  public ImageService(IEnumerable&lt;IImageProfile&gt; imageProfiles) {     ...     _imageProfiles = imageProfiles; } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u0432 \u043c\u0435\u0442\u043e\u0434 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0433\u0434\u0435 \u043c\u044b \u0432\u0441\u0451 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <code><b>ImageSharp<\/b><\/code>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 NuGet. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f <code><b>Image<\/b><\/code> \u0438 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/docs.sixlabors.com\/articles\/imagesharp\/index.html?tabs=tabid-1\" rel=\"nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a><\/p>\n<pre><code class=\"cpp\">public string SaveImage(IFormFile file, ImageType imageType) {     var imageProfile = _imageProfiles.FirstOrDefault(profile =&gt;                         profile.ImageType == imageType);      if (imageProfile == null)         throw new ImageProcessingException(&quot;Image profile has not found&quot;);      ValidateExtension(file, imageProfile);     ValidateFileSize(file, imageProfile);      var image = Image.Load(file.OpenReadStream());      ValidateImageSize(image, imageProfile);      var folderPath = Path.Combine(_hostingEnvironment.WebRootPath, imageProfile.Folder);      if (!Directory.Exists(folderPath))         Directory.CreateDirectory(folderPath);      string filePath;     string fileName;      do     {         fileName = GenerateFileName(file);         filePath = Path.Combine(folderPath, fileName);     } while (File.Exists(filePath));      Resize(image, imageProfile);     Crop(image, imageProfile);     image.Save(filePath, new JpegEncoder { Quality = 75 });      return Path.Combine(imageProfile.Folder, fileName); } <\/code><\/pre>\n<p>  \u0418 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0433\u043e \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u044e\u0442<\/p>\n<pre><code class=\"cpp\">private void ValidateExtension(IFormFile file, IImageProfile imageProfile) {     var fileExtension = Path.GetExtension(file.FileName);      if (imageProfile.AllowedExtensions.Any(ext =&gt; ext == fileExtension.ToLower()))         return;      throw new ImageProcessingException(Strings.WrongImageFormat); }  private void ValidateFileSize(IFormFile file, IImageProfile imageProfile) {     if (file.Length &gt; imageProfile.MaxSizeBytes)         throw new ImageProcessingException(Strings.ImageTooLarge); }  private void ValidateImageSize(Image image, IImageProfile imageProfile) {     if (image.Width &lt; imageProfile.Width || image.Height &lt; imageProfile.Height)         throw new ImageProcessingException(Strings.ImageTooSmall); }  private string GenerateFileName(IFormFile file) {     var fileExtension = Path.GetExtension(file.FileName);     var fileName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());      return $&quot;{fileName}{fileExtension}&quot;; }  private void Resize(Image image, IImageProfile imageProfile) {     var resizeOptions = new ResizeOptions     {         Mode = ResizeMode.Min,         Size = new Size(imageProfile.Width)     };      image.Mutate(action =&gt; action.Resize(resizeOptions)); }  private void Crop(Image image, IImageProfile imageProfile) {     var rectangle = GetCropRectangle(image, imageProfile);     image.Mutate(action =&gt; action.Crop(rectangle)); }  private Rectangle GetCropRectangle(IImageInfo image, IImageProfile imageProfile) {     var widthDifference = image.Width - imageProfile.Width;     var heightDifference = image.Height - imageProfile.Height;     var x = widthDifference \/ 2;     var y = heightDifference \/ 2;      return new Rectangle(x, y, imageProfile.Width, imageProfile.Height); } <\/code><\/pre>\n<p>  \u041f\u0430\u0440\u0443 \u0441\u043b\u043e\u0432 \u043e \u043c\u0435\u0442\u043e\u0434\u0435 <code><b>Resize<\/b><\/code>. \u0412 <code>ResizeOptions<\/code> \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <code>ResizeMode.Min<\/code>, \u044d\u0442\u043e \u0440\u0435\u0436\u0438\u043c, \u043a\u043e\u0433\u0434\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0430\u0439\u0437\u0438\u0442\u0441\u044f \u0434\u043e \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u043d\u044b \u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 1000\u04452000, \u0430 \u043c\u043e\u044f \u0446\u0435\u043b\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c 500\u0445500, \u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u0441\u0430\u0439\u0437\u0430 \u043e\u043d\u043e \u0441\u0442\u0430\u043d\u0435\u0442 500\u04451000, \u0437\u0430\u0442\u0435\u043c \u043e\u043d\u043e \u043e\u0431\u0440\u0435\u0437\u0430\u0435\u0442\u0441\u044f \u0434\u043e 500\u0445500 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n<p>  \u042d\u0442\u043e \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0451, \u043a\u0440\u043e\u043c\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430. \u041c\u0435\u0442\u043e\u0434 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443, \u043d\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 URL, \u0430 PATH \u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a: <code>logos\\\\yourFile.jpg<\/code>. \u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 PATH \u0441\u043a\u043e\u0440\u043c\u0438\u0442\u044c \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443, \u0442\u043e \u043e\u043d \u0441 \u044d\u0442\u0438\u043c \u0443\u0434\u0430\u0447\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u0442\u0441\u044f \u0438 \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0432\u0430\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u044d\u0442\u043e \u043e\u0442\u0434\u0430\u0434\u0438\u0442\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e, \u0442\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432\u044b \u043d\u0435 \u0443\u0432\u0438\u0434\u0438\u0442\u0435. \u041d\u0435 \u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u044d\u0442\u043e \u044f \u043f\u0440\u0438\u043d\u044f\u043b \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u0411\u0414 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e PATH, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0444\u0430\u0439\u043b\u0443, \u0435\u0441\u043b\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u0430 \u0432 DTO, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u043b\u0435\u0442\u0430\u0435\u0442 \u043d\u0430 \u0444\u0440\u043e\u043d\u0442 \u044f \u043c\u0430\u043f\u043b\u044e \u044d\u0442\u043e \u043f\u043e\u043b\u0435, \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u044f \u0435\u0433\u043e \u0432 URL. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 extension \u043c\u0435\u0442\u043e\u0434 <\/p>\n<pre><code class=\"cpp\">public static string PathToUrl(this string path) {     return path?.Replace(&quot;\\\\&quot;, &quot;\/&quot;); } <\/code><\/pre>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043f\u0438\u0448\u0438\u0442\u0435 \u0447\u0438\u0441\u0442\u044b\u0439 \u043a\u043e\u0434 \u0438 \u043d\u0435 \u0431\u043e\u043b\u0435\u0439\u0442\u0435!<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/503028\/\"> https:\/\/habr.com\/ru\/post\/503028\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/503028\/\">\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0441\u0432\u043e\u0451\u043c \u043e\u043f\u044b\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0432 .NET Core \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0438\u0445 \u0440\u0435\u0441\u0430\u0439\u0437\u043e\u043c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u0414\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/SixLabors\/ImageSharp\" rel=\"nofollow\">ImageSharp<\/a> \u043e\u0442 Six Labors. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438, \u043d\u043e \u0442.\u043a. \u044f \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u0438 \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. \u041d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u043e\u043d\u0438 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 \u0440\u0435\u043b\u0438\u0437-\u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u0430, \u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e \u0443\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. <br \/>  \u0417\u0430\u0434\u0430\u0447\u0435\u0439 \u0431\u044b\u043b\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u0444\u0440\u043e\u043d\u0442\u0430, \u043e\u0431\u0440\u0435\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u0440\u043e\u043d \u0438 \u0440\u0435\u0441\u0430\u0439\u0437\u0438\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0435 \u0441\u044a\u0435\u0434\u0430\u043b\u043e \u043c\u043d\u043e\u0433\u043e \u0434\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430, \u0432\u0435\u0434\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0433\u0430\u0431\u0430\u0439\u0442 \u0432 \u043e\u0431\u043b\u0430\u043a\u0435 \u2014 \u044d\u0442\u043e \u0434\u0435\u043d\u044c\u0433\u0438.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-304032","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/304032","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=304032"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/304032\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=304032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=304032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=304032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}