Angularjs:错误:'追加'对未实现接口FormData的对象调用.jQuery.param/ad

Angularjs: Error: 'append' called on an object that does not implement interface FormData. jQuery.param/add

本文关键字:调用 对象 jQuery ad param 实现 追加 错误 接口 Angularjs FormData      更新时间:2023-10-05

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

HTML

<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);
                        });
                };

图像查找服务

  ]).factory('imageFind', [
        'imageService', 'ApiService',
        function (imageService, ApiService) {
            return {
                search: function (file, start, sort) {
                    var formData, params={};
                     if (start == null) {
                        start = 0;
                     }
                     if (sort == null) {
                        sort = "";
                     }
                    var data = {
                        start: start,
                        sort: sort
                    };
                    data = $.param(data);
                    var config = {'Content-Type': undefined};
                    return ApiService.post(imageFindPint, data, config);
                }
            };
        }
    ]);

上传图像时出现以下错误:错误:在未实现接口FormData的对象上调用了"append"。jQuery.param/add

你看到我做错什么了吗?

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

这应该能解决问题。

在控制器中//file=new FormData();//file={'file':文件};

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