Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How upload a file with AngularJS, asp.net web API and fileupload saving to SQL

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

The nearest I've found is this post which seems quite good but limited to images but struggling to follow as its a bit confusing knowing which responses work. AngularJS .Net WebAPI Upload image and save to database (MSSQL).

What I would like to do very simply is have an Object with properties Name (string) and Logo (Logo stored in db binary field). From and angular view save the object (calling route of my Web API) including validating the name and saving an image and if it already has one, display the current image.

If anyone knows of a good simple example that will achieve that and ideally will work for any kind of file as some uploads in my site might be PDFs for example I would be hugely grateful.

like image 618
RichardB Avatar asked Mar 31 '16 20:03

RichardB


1 Answers

I've used ng-file-upload in quite a few Angular projects with no problems. It has comprehensive documentation and many examples to get you started.

The have recipes for the server side stuff too, here is one for .NET

This answer will help on the controller side in terms of getting the uploaded files into a byte array that you can then insert into the database of your choice.

like image 59
Aleks Avatar answered Oct 22 '22 11:10

Aleks