Angularjs:错误:在没有实现接口FormData的对象上调用'append'。 jQuery.param /加

时间:2016-03-31 12:41:44

标签: javascript angularjs file-upload ng-file-upload

我正在使用https://github.com/danialfarid/ng-file-upload插件管理我的文件上传,以下是我的代码。

HTML

import sys
try:
    from io import StringIO
except:
    from StringIO import StringIO

stdout = sys.stdout
sys.stdout = StringIO()

ARGS = ["-r","n", "--rcfile=rcpylint"]
r = lint.Run(['../test.py']+ARGS, exit=False)

test = sys.stdout.getvalue()
sys.stdout.close()
sys.stdout = stdout

print (test.split('\n'))

控制器

<form name="form">
    Single Image with validations
    <div class="button" ngf-select ng-model="file" name="file" ngf-pattern="'image/*'"
         ngf-accept="'image/*'" ngf-max-size="20MB" ngf-min-height="100"
         ngf-resize="{width: 100, height: 100}">Select</div>
    Multiple files
    <div class="button" ngf-select ng-model="files" ngf-multiple="true">Select</div>
    Drop files: <div ngf-drop ng-model="files" class="drop-box">Drop</div>
    <button type="submit" ng-click="upload()">submit</button>
</form>

图片查找服务

// upload on file select or drop
                $scope.upload = function (file) {

                    file = new FormData();
                    file = {'file': file};


                    imageFind.search(file, $scope.documentsOffsetStart, $scope.titleSorting)
                        .then(
                        function (response) {
                            console.log('Success ' + response.config.data.file.name + 'uploaded. Response: ' + response.data);
                        },
                        function (response) {
                            console.log('Error status: ' + response.status);
                        }, function (evt) {
                            console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
                        });

                };

图片上传时出现以下错误: 错误:对未实现接口FormData的对象调用'append'。 jQuery.param /添加

你知道我做错了吗?

1 个答案:

答案 0 :(得分:1)

通过<button type="submit" ng-click="upload('file')">submit</button>

这应该可以解决问题。

在控制器中 // file = new FormData(); // file = {&#39; file&#39;:file};

可以删除,但需要将FormData()添加到服务。