File upload and download in ASP .NET Core 6.0 Web API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome guys in this session we are going to discuss one more interesting topic in.net core 6.0 web API that is file upload and download so how we can upload file in our web API and how we can download this that file from the web API I have already created two videos for upload and download for dotnet core 3.1 I will give the link on the video description if you are interested please check it out guys before starting the session if you are new to my channel please hit the Subscribe button ring the bell icon for future notification and if you ended up liking my video give me a like and give me your suggestion in the comment box let's get started so for today's session I am using visuals to 2022 I am creating a.net core web API project thank you so I'm giving file upload download okay next I'm keeping.net core 6.0 and for now I'm not keeping https click on create so give it for few minutes it will be it okay our application got created so we have our in our controller weather forecast controller program.csn weather forecast this model I am adding one more controller here which is be used for file log float and download so I am adding web API empty controller and giving the controller name is files controller I need of this route now my fast my thing is to create a API to upload our file so we have created a API upload file and the response type will be 200 okay and 400 bed request it will accept parameter I from file this iPhone file is from the interface asp.net code.http iPhone file m a cancellation token here I am going to upload my file and I am going to upload into my solution or in the server so for that I am adding one more method to upload the file so I have added this method which is a private async task of string right file it is also accepting this from file form file and here I am taking the extension from the file name dot split by splitting the DOT next I am going to upload into my application upload slash files folder if it is exist or if it is not existing it will create the directory or as it will skip this part and it will come to our path to write so using a stream file stream I am writing to the specified path so let's create a path on Sim like I am going to so this is my upload and one more English file so inside this I am there will be one folder and that folder name will be files so now I'm I make file upload part is done we are not using any external nuget packages equal to and it will accept this parameter now let's and now it will return my file name so now let's run the application and see it is uploading and getting our file name or not excuse me on City Salon in the Swagger UI will come so our application got around we have post upload file API we have created try it out here you can see so let's I'm adding this particular thumbnail Okay now click on execute so you can see it's coming a response body a PNG file name right now stop the application from running go to solution Explorer in the files you can see it is uploaded in this way we can upload our file to our web API now next tax is to response or to download the file how we can do this so again site one more API so we have a API Name download file it will accept the file name so that PNG file that where time dot tick so we have given that time now dot x dot extension so it will accept that file name and it will download it for that I am taking this path so this will be same okay so in the combined section also here I am taking adding the file name which is user will require paste okay next I am taking a provider which is a file extension content time provider we need to add a using statement Microsoft asp.net code.static file right now if provider try get content type content type will be post OCT stream next thing getting the bytes read all by from this file path then it will return the byte content type which is a stream in the file name now run the application and see reworking properly or not so first let's see upload file ah there's upload a different image so I am uploading this today's session thumbnail YouTube thumbnail so we got our file name now if we go to our download file API so here if we are giving try it out give the file name execute so you can see download file is coming so this is our thumbnail so in this way we can upload and download file in our DOT net code web API application guys if you like this session give me a like and share this video with your friends thank you very much and one more thing I will just source code link on the video description please download and check it out thank you
Info
Channel: Biswa Ranjan
Views: 9,256
Rating: undefined out of 5
Keywords: File upload and download in ASP .NET Core 6.0 Web API, File upload and download in ASP .NET Core Web API, .NET Core 6.0, .NET Core 6.0 Web API, Learn .NET Core 6.0 Web API, Learn .NET Core 6.0, .NET Core 6.0 Web API Tutorial, .NET Core 6.0 Tutorial, File upload and download in ASP Dot NET Core Web API, Dot NET Core 6.0, DotNET Core 6.0 Web API, Learn DotNET Core 6.0 Web API, Learn Dot NET Core 6.0, Dot NET Core 6.0 Web API Tutorial, Dot NET Core 6.0 Tutorial
Id: xZV42p9QCh8
Channel Id: undefined
Length: 8min 4sec (484 seconds)
Published: Mon Jan 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.