How to upload a file using AngularJS, asp.net web API and saving files in SQL

I am from the background of web forms and learning angular with a web API in C #, and I have a working site for adding / editing and deleting an object record. I know that I want to move on to more complex issues, but I'm struggling to figure out where to start!

The closest I found is a message that seems pretty good, but limited to images, but struggles to follow its slightly confusing knowledge of which answers work. AngularJS.Net WebAPI Upload Image and Save to Database (MSSQL) .

What I would like to do very simply has an object with Name (string) properties and a logo (the logo is stored in a binary binary field). From and angular view the saving of the object (calling the route of my web API), including checking the name and saving the image, and if it already exists, display the current image.

If anyone knows of a good simple example that will achieve this and ideally work for any file, since some of the downloads on my site may be PDF files, for example, I would be very grateful.

+5
source share
1 answer

I used ng-file-upload in a number of Angular projects without any problems. It contains comprehensive documentation and many examples to help you get started.

You have recipes for the server side, here for .NET.

This answer will help on the controller side in terms of getting the downloaded files into an array of bytes, which can then be inserted into the database of your choice.

+10
source

Source: https://habr.com/ru/post/1246187/


All Articles