Я использую Angular для клиентской части и использую ASP.NET Core в бэкэнде.
Мне нужно загрузить изображение в ASP.NET Core, и я использую этот код:
private readonly IApplicationRootSiteData _applicationRoot;
private readonly IHostingEnvironment _hostingEnvironment;
/// <summary>
/// Constructor
/// </summary>
/// <param name="hostingEnvironment"></param>
/// <param name="applicationRoot"></param>
public UploadController(
IHostingEnvironment hostingEnvironment,
IApplicationRootSiteData applicationRoot)
{
_hostingEnvironment = hostingEnvironment;
_applicationRoot = applicationRoot;
}
/// <summary>
/// Upload Picture
/// </summary>
/// <returns></returns>
[HttpPost("UploadNewsPic"), DisableRequestSizeLimit]
public IActionResult UploadNewsPic()
{
var file = Request.Form.Files[0];
try
{
if (!Directory.Exists(Path.Combine(_hostingEnvironment.WebRootPath, _applicationRoot.ProductMainPictureFolder)))
{
if (!Directory.Exists(Path.Combine(_hostingEnvironment.WebRootPath, _applicationRoot.RootPath)))
{
Directory.CreateDirectory(Path.Combine(_hostingEnvironment.WebRootPath, _applicationRoot.RootPath));
}
if (!Directory.Exists(Path.Combine(_hostingEnvironment.WebRootPath, _applicationRoot.UploadProductPicturePath())))
{
Directory.CreateDirectory(Path.Combine(_hostingEnvironment.WebRootPath, _applicationRoot.UploadProductPicturePath()));
}
if (!Directory.Exists(Path.Combine(_hostingEnvironment.WebRootPath, _applicationRoot.UploadProductMainPicturePath())))
{
Directory.CreateDirectory(Path.Combine(_hostingEnvironment.WebRootPath, _applicationRoot.UploadProductMainPicturePath()));
}
}
if (file.Length > 0)
{
string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
string fullPath = Path.Combine(_applicationRoot.UploadNewPath(), file.Name);
using (var stream = new FileStream(fullPath, FileMode.Create))
{
file.CopyTo(stream);
}
}
return Ok();
}
catch (Exception e)
{
return BadRequest();
}
}
}
и это класс запуска:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseCustomExceptionHandler();
if (env.IsDevelopment())
{
//app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler();
app.UseHsts();
}
app.AddSwaggerUI();
app.UseCors("CorsPolicy");
app.UseHttpsRedirection();
app.UseSwagger();
app.UseAuthentication();
app.UseStaticFiles();
app.UseMvc();
}
но когда я отправляю запрос в ASP.NET Core, я получаю эту ошибку:
ОПЦИИ https://localhost:44390//api/v1/Upload/UploadNewsPic
Net :: ERR_CONNECTION_REFUSED
В чем проблема? Как я могу решить это?