Angularjs $http post file and form data

后端 未结 8 1160
广开言路
广开言路 2020-11-28 22:14

I have the below request in python

import requests, json, io

cookie = {}
payload = {\"Name\":\"abc\"}
url = \"/test\"
file = \"out/test.json\"

fi = {\'file         


        
8条回答
  •  广开言路
    2020-11-28 22:51

    I recently wrote a directive that supports native multiple file uploads. The solution I've created relies on a service to fill the gap you've identified with the $http service. I've also included a directive, which provides an easy API for your angular module to use to post the files and data.

    Example usage:

    
    

    You can find the code on github, and the documentation on my blog

    It would be up to you to process the files in your web framework, but the solution I've created provides the angular interface to getting the data to your server. The angular code you need to write is to respond to the upload events

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

提交回复
热议问题