symfony - Uploading Files using AngularJS and symfony2 -
i used angularjs example provided in http://jsfiddle.net/jejenny/zg9re/ upload file local machine. work angularjs(frontend) , symfony2(backend),and have send email attachement(as rest web service) have problem,i didn't email attachment,this error in console:
this code:
<div ng-controller="mailnewctrl1"> <input type="file" nv-file-select="" id="id_file" uploader="uploader" file-model="myfile" > <button id="id_submit" class="btn btn-info w-xs" ng-click='usersend();'>send</button></div>
and controller:
'use strict'; angular.module('app', [ 'nganimate', 'ngcookies', 'ngresource' ]) .controller('mailnewctrl1', ['$scope', '$http' ,'fileupload' , function($scope,$http,fileupload) { $scope.errors = []; $scope.msgs = []; $scope.usersend = function() { $scope.errors.splice(0, $scope.errors.length); // remove error messages $scope.msgs.splice(0, $scope.msgs.length); var file = $scope.myfile; console.log('file ' + json.stringify(file)); var uploadurl = "/fileupload"; fileupload.uploadfiletourl(file, uploadurl); $http({method: 'post', url: 'theurlsendmail?myfile='+file}).success(function(data, status, headers, config){ if (data.msg != '') { $scope.msgs.push(data.msg); alert("sucess send"); } else { $scope.errors.push(data.error); } }).error(function(data, status) { // called asynchronously if error occurs // or server returns response error status. $scope.errors.push(status); }); } }]); app.directive('filemodel', ['$parse', function ($parse) { return { restrict: 'a', link: function(scope, element, attrs) { var model = $parse(attrs.filemodel); var modelsetter = model.assign; element.bind('change', function(){ scope.$apply(function(){ modelsetter(scope, element[0].files[0]); }); }); } }; }]); app.service('fileupload', ['$http', function ($http) { this.uploadfiletourl = function(file, uploadurl){ var fd = new formdata(); fd.append('file', file); $http.post(uploadurl, fd, { transformrequest: angular.identity, headers: {'content-type': undefined} }) .success(function(){ }) .error(function(){ }); } }]);
i cheked rights on folder store,it contains privilages
thanks help
Comments
Post a Comment