Lionel Bovy
Lionel Bovy
CC#
Created by Lionel Bovy on 3/15/2024 in #help
✅ Which Nuget ASP.NET Core Versioning package to choose?
Hi, I need to do some versioning on an API with ASP.NET Core (.NET 6), but I don't know which package to choose. I'd be tempted to install the "ASP.NET Web API" package, but I don't quite understand when there's an HttpConfiguration (https://github.com/dotnet/aspnet-api-versioning/wiki/New-Services-Quick-Start#aspnet-web-api) in the Program.cs. When I look at the example, I get the impression that it uses an older version of ASP.NET Core.
11 replies
CC#
Created by Lionel Bovy on 12/2/2023 in #help
Serving static files via a Web API (REST)
Hello, I'd like to set up an image upload system via a REST API in ASP.NET Core 6. I tried to configure my Program.cs, but when I try to get the path via the environment in my service, it's set to Microsoft.Extensions.FileProviders.NullFileProvider and I get a null path. Here's my Program.cs: https://pastebin.com/9hJmEKJn Here is the code where I encounter the problem:
public class LocalFileUploadService : IFileUploadService
{
private readonly IWebHostEnvironment _environment;

public LocalFileUploadService(IWebHostEnvironment environment)
{
_environment = environment;
}

public async Task<string> UploadFileAsync(IFormFile file, string fileName)
{
var fileExtension = Path.GetExtension(file.FileName);
var filePath = Path.Combine(_environment.WebRootPath, "uploads", fileName + fileExtension);

using (var fileStream = new FileStream(filePath, FileMode.Create))
{
await file.CopyToAsync(fileStream);
}

return fileName;
}

// ...
}
public class LocalFileUploadService : IFileUploadService
{
private readonly IWebHostEnvironment _environment;

public LocalFileUploadService(IWebHostEnvironment environment)
{
_environment = environment;
}

public async Task<string> UploadFileAsync(IFormFile file, string fileName)
{
var fileExtension = Path.GetExtension(file.FileName);
var filePath = Path.Combine(_environment.WebRootPath, "uploads", fileName + fileExtension);

using (var fileStream = new FileStream(filePath, FileMode.Create))
{
await file.CopyToAsync(fileStream);
}

return fileName;
}

// ...
}
4 replies
CC#
Created by Lionel Bovy on 10/21/2023 in #help
❔ OAuth (3-layer architecture app)
Hi, I'm a student at a university and we need to create an application that, among other things, implements an OAuth via Google, for example. My problem is that I don't know where and how to manage this OAuth because I have a front-end written in Vue 3 and a REST API made with ASP.NET Core (.NET 6) and Identity. Should I delegate this part to the front-end or to the REST API? Because from what I understood, I need to get a token that I'll exchange with the REST API, which will then contact Google to retrieve the user's information.
22 replies