I tried this for a few days. Assuming I have the following form:
<form ng-submit="create()" class="form-horizontal" enctype="multipart/form-data"> <div class="control-group"> <label class="control-label">name : </label> <div class="controls"> <input type="text" class="input-xlarge" ng-model="message.title" /> </div> </div> <div class="control-group"> <label class="control-label">avatar : </label> <div class="controls"> <input type="file" ng-model="message.avatar" name="message[avatar]" /> </div> </div> <div class="well"> <input class="btn btn-large btn-primary" type="submit" value="ε»Ίη«θ³ζ" /> </div> </form>
I use a carrier gem to handle file loading behind the scenes. My controller is as follows:
$scope.create = function($scope.message){ var deferred = $q.defer(); $http({ method: 'POST', url: '/resources/messages', data: $.param({message: message}), headers: {'Content-Type': 'multipart/form-data'} }). success(function(data, status, headers, config){ deferred.resolve(data); }). error(function(data, status, headers, config){ deferred.reject(status); }); return deferred.promise; };
However, it does not work. What I intend to do is create a form and upload everything like the old one, but the examples I found, such as ng-upload, or like this post , or jquery file upload , they do not suit me. Is there any example or code sample for this purpose? Thanks.
source share