龙卷风 - 当angularjs上传图片时空json

时间:2017-03-28 08:03:39

标签: python angularjs image upload tornado

在我的Html文件中:

 <div class="col-sm-10">
          <div ngf-drop ngf-select ng-model="files" class="drop-box" 
            ngf-drag-over-class="'dragover'" ngf-multiple="true" ngf-allow-dir="true"
            accept="image/*,application/pdf" 
            ngf-pattern="'image/*,application/pdf'">Drop pdfs or images here or click to upload</div>
        <div ngf-no-file-drop>File Drag/Drop is not supported for this browser</div>
        </div>

在我的Angularjs文件中:

app.controller('registerController', ['$scope', '$http', 'Upload', '$timeout', function($scope, $http, Upload, $timeout) {
  $scope.$watch('files', function() {
    $scope.upload($scope.files);
  })

  $scope.$watch('file', function () {
      if ($scope.file != null) {
        $scope.files = [$scope.file]; 
    }
});

  $scope.upload = function (files) {
    if (files && files.length) {
        for (var i = 0; i < files.length; i++) {
          var file = files[i];
          if (!file.$error) {
            Upload.http({
                method: 'POST',
                url: '/upload',
                data: {
                   username: 'Testing',
                   file: file
                }                    
            }).then(function (response) {
                console.log(response)
            }, function errorCallback(response) {
              console.log('Error: ' + response)
            });
          }
        }
    }
};

在我的python文件中:

class UploadHandle(tornado.web.RequestHandler):
    def post(self):
        userData = json.loads(self.request.body)
        print userData

然后,我的python结果显示出来了 {&#34;用户名&#34;:&#34;测试&#34;&#34;文件&#34;:{}}

我可以获取用户名,但为什么我的文件返回空值?

0 个答案:

没有答案