If you want to learn how to add swagger in ASP.Net Core then check my previous post. In this post, I will show you how to customize swagger UI to upload a file in ASP.Net Core Web API project. First, let’s add an action which will be responsible to upload a file in our API. If you want to know more about how to upload a file (from Postman) and save it in Azure storage then check my previous post.
In this post, I will show how to upload a file in ASP.NET Core API and store it in Azure storage as a blob.
To accept file you can use IFormFile type object. Based on your requirement you can use IFormFile or ICollection<IFormFile> type as a parameter for API action. IFormFile exposes properties like FileName, Name, ContentDisposition, Length and other many more useful properties and methods.
In this post i will show how to add, configure and customize swagger in ASP.NET Core web API project.
Let’s start by creating new ASP.NET Core web API project and adding swagger in our project. For .NET there is open source project swashbuckle which provide swagger implementation. We need to get it from nuget.
.Net Core introduces secret manager tool to store user secrets during development which helps developer to manage secrets and other sensitive settings during development in different space/file rather than on appsettings.json. You shouldn’t store id, secret keys, passwords or any other sensitive data in source code instead you have to store it other separate file and for this secret manager tool comes to be a handy tool. It helps to prevent sensitive data from being checked in by source control. ASP.NET Core also use this tool to manage user secrets during development. With secret manager tool you can associate app secrets with a specified project and share them across multiple projects. User secrets are stored as JSON data (like you see on appsettings.json).
First let’s know about what is Dependency Injection and why we need this.
Dependency injection is a software design pattern that implements inversion of control for resolving dependencies. A dependency is an object that can be used (a service). An injection is the passing of a dependency to a dependent object (a client) that would use it. DI is widely adopted because this technique helps developer for achieving loose coupling between objects and its collaborators, or dependencies. Rather than directly instantiating collaborators, or using static references, the objects a class needs in order to perform its actions are provided to the class in some fashion. Mostly there are three common approach to achieve DI Setter, Interface, and Constructor. [Wikipedia]
.Net Core 1.0 is RTMed along with ASP.NET Core 1.0, EntityFramework 1.0 and Visual Studio 2015 update 3 on June 27 2016. For .Net developer this is an awesome moment not only due to RTM of another product but its more than that. “This” .NET Core runs every where, can develop application from editor of choice, able to work with dotnet cli etc. etc.
As a developer you probably had to make user account system where you kept user login credentials (along with other personal details). If you are still using old style like storing password in plain text or using any other weak password encryption technique like AES then your user’s data is in risk. That’s an easy way for hacker. So hashing is another secure crypto technique/algorithm to implement for security.
HTTP is a stateless protocol. To allow users save to state information across requests, ASP.NET provides Session storage. The session variables are stored on per-user basis. In ASP classic, you can store session variables only in the Web server’s memory. However, this approach proves to be poor in terms of scalability and reliability. In later versions of ASP.NET you can customize the session state store as per your requirement. This article will explore one of the scalable and reliable approaches for storing session variables — Azure Redis Cache.
In this post i will show how to extract thumbnail form file. For this post i wrote sample code for extracting thumbnail from images and display image of Song. So here are three simple step to perform the task. Continue Reading