“上传器”必须是FileUploader

时间:2016-07-11 09:51:02

标签: angularjs angularjs-directive

我提到了这一点:https://github.com/nervgh/angular-file-upload/tree/version-3.0.0-alpha

angular.min.js:14540 TypeError: "Uploader" must be an instance of FileUploader
    at link (http://localhost:8080/services/angular-file-upload.js:1874:24)
    at invokeLinkFn (http://localhost:8080/lib/js/angular.min.js:10445:8)
    at nodeLinkFn (http://localhost:8080/lib/js/angular.min.js:9733:9)
    at compositeLinkFn (http://localhost:8080/lib/js/angular.min.js:8712:10)
    at compositeLinkFn (http://localhost:8080/lib/js/angular.min.js:8717:10)
    at compositeLinkFn (http://localhost:8080/lib/js/angular.min.js:8717:10)
    at compositeLinkFn (http://localhost:8080/lib/js/angular.min.js:8717:10)
    at compositeLinkFn (http://localhost:8080/lib/js/angular.min.js:8717:10)
    at publicLinkFn (http://localhost:8080/lib/js/angular.min.js:8567:9)
    at link (http://localhost:8080/lib/js/angular-route.js:1053:5) <input type="file" nv-file-select="" uploader="uploader" multiple="">

4 个答案:

答案 0 :(得分:1)

试试这个

<element ng-if="uploader">
    <input type="file" nv-file-select uploader="uploader" multiple />
</element>

我在angular-file-upload v2.3.4上测试过并且工作正常

答案 1 :(得分:1)

FileUploader应位于控制器全局范围内,以便使对象成为FileUploader。我做了一个工厂并在整个控制器中使用它。

答案 2 :(得分:0)

这是js部分,这是我在这些中写的服务,你可以传递FileUploader对象和url以及$ scope变量。

tmsApp.service("fileServices", function($http) {

    this.uploadFile = function(FileUploader, $scope, url) {
        var uploader = $scope.uploader = new FileUploader({
            url : url,
        });
        // FILTERS
        uploader.filters.push({
            name : 'customFilter',
            fn : function(item, options) {
                return this.queue.length < 10;
            }
        })
    }

})

这是.java文件

/**
 * 
 * @param file
 * @param projectId
 * @param taskId
 * @comments
 */
public void fileUpload(MultipartFile file, Long projectId, String taskId) {
    if (!file.isEmpty()) {
        try {
            String uploadsDir = location + "/uploads/" + "tenant/"
                    + authUtilService.getLoggedInUsersTenantName()
                    + "/project/" + projectId + "/task/" + taskId + "/";

            if (!new File(uploadsDir).exists()) {
                new File(uploadsDir).mkdirs();
                log.info("Directory Created");
            }
            log.info("realPathtoUploads = {}", uploadsDir);
            String originalFileName = file.getOriginalFilename();
            String filePath = uploadsDir + originalFileName;
            File destination = new File(filePath);
            file.transferTo(destination);

            Task task = taskRepository.findByIdAndTenant(taskId,
                    authUtilService.getLoggedInUsersTenant());
            taskHistoryService.addAuditUtility(TaskAudit.FILE, task,
                    originalFileName);

        } catch (Exception e) {
        }

    } else {
        log.info("File upload Failed!! Try again.....");
    }
}

答案 3 :(得分:0)

我收到了这个错误,因为在我决定使用这个库并忘记它之前我已经在底部定义了另一个$ scope.uploader方法......

在注意之前先尝试其他所有内容,最好的是xD