2

I need to save a PDF file which the user uploads to database as a byte array (in Angular JS). I have tried using the file upload module provided by Angular. It doesnt seem to work for me.I have also tried posting the PDF file through a $http post call of jquery. This method works if I accept the data at the server side as a dynamic object of Newtonsoft. However I need a byte array and I am unable to convert this object to a byte array.

2 Answers2

0

This questions is not really about angular but instead it is, based on your description, about how to upload a file using WebApi.

I would recommend your start trying to upload your file using this exmaple:

http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx

When it is ready then adapting it to your angular app.

Dalorzo
  • 19,834
  • 7
  • 55
  • 102
  • I have tried this method but it enables to write to a certain path on the server. What I want is, to send the file in the form of array of bytes to the API controller so that I can save it in SQL database in that format. As a work around I could use this method to write to a path on the server first, then read it as byte array and save it to database. But is there any other faster approach? – user3264738 Feb 06 '14 at 07:44
0

I had a similar issue a while back. Have a look at this Stack Overflow link.

Uploading/Downloading Byte Arrays with AngularJS and ASP.NET Web API

If you still have some questions, let me know.

I am sending and receiving a lot of byte array data between my clients and servers using Web API. The approach I use is compatible with iPhones, iPad, Android devices, Macs, and Windows PCs/laptops. I haven't checked it on Windows phones yet, but do not expect any problems.

Regards....

Community
  • 1
  • 1
Highdown
  • 646
  • 1
  • 11
  • 23