I'm using AngularJS to interact with a RESTful webservice, using Restangular to abstract the various entities exposed. Some of this entities are images or files, so I need to be able to use the post action of Restangular to send both binary data and text fields within the same request.
How can I use Restangular to send data with uploaded images or files, to a restful webservice in a single POST request?
I just answered a very similar question here which explains how to use a file-model directive and creating a formData object which then is posted to an api.
Using Restangular instead of $http, the only part that's different is of course how the post is done.
Here is how the post is done using restangular:
Restangular.one('api/url/to/endpoint')
.withHttpConfig({transformRequest: angular.identity})
.customPOST(fd, '', undefined, {'Content-Type': undefined})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With