Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restangular POST files and data

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?

like image 261
Hegler Avatar asked Nov 05 '14 12:11

Hegler


1 Answers

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})
like image 160
Erik Svedin Avatar answered Oct 18 '22 21:10

Erik Svedin