Posts

Showing posts with the label Asp.Net Web Api

ASP Core WebApi Test File Upload Using Postman

Image
Answer : Thanks to @rmjoia's comment I got it working! Here is what I had to do in Postman: The complete solution for uploading file or files is shown below: This action use for uploading multiple files : // Of course this action exist in microsoft docs and you can read it. HttpPost("UploadMultipleFiles")] public async Task<IActionResult> Post(List<IFormFile> files) { long size = files.Sum(f => f.Length); // Full path to file in temp location var filePath = Path.GetTempFileName(); foreach (var formFile in files) { if (formFile.Length > 0) using (var stream = new FileStream(filePath, FileMode.Create)) await formFile.CopyToAsync(stream); } // Process uploaded files return Ok(new { count = files.Count, path = filePath}); } The postman picture shows how you can send files to this endpoint for uploading multiple files: This action use for uploading single file : [Http...

AspNetCore.Mvc.Core Version Mismatch

Answer : <PackageReference Include="Microsoft.AspNetCore.App" /> I had the same issue, after add this line to unit test project, it start pick right version of Microsoft.AspNetCore.App. Update The issue noted below has been fixed & you should be able to benefit from implicit package versioning and reference like below without providing the version number of the package. <PackageReference Include="Microsoft.AspNetCore.App" /> Original Answer This issue is because of the Implicit Versioning that was introduced for Microsoft.AspNetCore.App metapackage. With implicit versioning the sdk decides the version & it resolved it as 2.1.1 However, it was resolving to version 2.1 for the nunit test project. Specifying the version number for the nunit project like <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1"/> and performing dotnet restore helped resolve this issue. There is a ticket for thi...