Olá, pessoal. Estou tendo problemas com o seguinte erro
Content root path: C:\Users\augus\OneDrive\Documentos\FORMAÇÕES ALURA\C#\FORMAÇÃO - C# Web crie aplicações usando ASP.NET\ScreenSound web\ScreenSound.API
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.IO.FileNotFoundException: Could not find file 'C:\Users\augus\OneDrive\Documentos\FORMAÇÕES ALURA\C#\FORMAÇÃO - C# Web crie aplicações usando ASP.NET\ScreenSound web\ScreenSound.API\wwwroot\FotosPerfil\26052024131010.teste.jpeg'.
File name: 'C:\Users\augus\OneDrive\Documentos\FORMAÇÕES ALURA\C#\FORMAÇÃO - C# Web crie aplicações usando ASP.NET\ScreenSound web\ScreenSound.API\wwwroot\FotosPerfil\26052024131010.teste.jpeg'
at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
at System.IO.FileStream..ctor(String path, FileMode mode)
at ScreenSound.API.Endpoints.ArtistasExtensions.<>c.<<AddEndPointsArtistas>b__0_2>d.MoveNext() in C:\Users\augus\OneDrive\Documentos\FORMAÇÕES ALURA\C#\FORMAÇÃO - C# Web crie aplicações usando ASP.NET\ScreenSound web\ScreenSound.API\Endpoints\ArtistasExtensions.cs:line 50
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Http.RequestDelegateFactory.ExecuteTaskResult[T](Task`1 task, HttpContext httpContext)
at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass102_2.<<HandleRequestBodyAndCompileRequestDelegateForJson>b__2>d.MoveNext()
--- End of stack trace from previous location ---
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
Eu peguei o caminho citado e fiz a busca no explorador de arquivos, a pasta existe: Meu metodo MapPost esta assim:
app.MapPost("/Artistas", async ([FromServices] IHostEnvironment env, [FromServices] DAL<Artista> dal, [FromBody] ArtistaRequest artistaRequest) =>
{
var nome = artistaRequest.nome.Trim();
var imagemArtista = DateTime.Now.ToString("ddMMyyyyHHmmss") + "." + nome + ".jpeg";
var path = Path.Combine(env.ContentRootPath, "wwwroot", "FotosPerfil", imagemArtista);
var directory = Path.GetDirectoryName(path);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
using MemoryStream ms = new MemoryStream(Convert.FromBase64String(artistaRequest.fotoPerfil!));
using FileStream fs = new(path, FileMode.Create);
await ms.CopyToAsync(fs);
var artista = new Artista(artistaRequest.nome, artistaRequest.bio)
{
FotoPerfil = $"/FotosPerfil/{imagemArtista}"
};
dal.Adicionar(artista);
return Results.Ok();
});
Caso alguem consiga me ajudar, agradeço :)