“Uploader” must be an instance of FileUploader

那年仲夏 提交于 2019-12-06 04:18:13

try with this

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

I tested on angular-file-upload v2.3.4 and works fine

FileUploader should be in controllers global scope in order to make an object respective to FileUploader. I made a factory and used it throughout the controller.

This is the js part, this is the service i wrote in these you can pass the FileUploader object and the url along with $scope variable.

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

})

This is the .java file

/**
 * 
 * @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.....");
    }
}

I was getting this error because I had defined an other $scope.uploader way at the bottom from before I decided to use this library and had forgotten about it...

Was trying everything else out first before noticing, the best ones xD

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!