javascript - Angularjs $http post file and form data -


i have below request in python

import requests, json, io  cookie = {} payload = {"name":"abc"} url = "/test" file = "out/test.json"  fi = {'file': ('file', open(file) )} r = requests.post("http://192.168.1.1:8080" + url, data=payload, files=fi, cookies=cookie) print(r.text) 

which send file, , form fields backend. how can same (sending file + form fields) angular $http. currently, this, not sure how send file too.

var payload = {"name":"abc"}; $http.post('/test', payload)     .success(function (res) {     //success }); 

i wrote directive supports native multiple file uploads. solution i've created relies on service fill gap you've identified $http service. i've included directive, provides easy api angular module use post files , data.

example usage:

<lvl-file-upload     auto-upload='false'     choose-file-button-text='choose files'     upload-file-button-text='upload files'     upload-url='http://localhost:3000/files'     max-files='10'     max-file-size-mb='5'     get-additional-data='getdata(files)'     on-done='done(files, data)'     on-progress='progress(percentdone)'     on-error='error(files, type, msg)'/> 

you can find code on github, , documentation on my blog

it process files in web framework, solution i've created provides angular interface getting data server. angular code need write respond upload events

angular     .module('app', ['lvl.directives.fileupload'])     .controller('ctl', ['$scope', function($scope) {         $scope.done = function(files,data} { /*do when upload completes*/ };         $scope.progress = function(percentdone) { /*do when progress reported*/ };         $scope.error = function(file, type, msg) { /*do if error occurs*/ };         $scope.getadditionaldata = function() { /* return additional data posted server*/ };      }); 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -