0

我们的应用程序使用 ng-flow 来上传文件。当我们尝试上传多个文件时,它会为每个文件进行单独的后端调用。因此,如果我们上传 100 个文件,则会进行 100 次后端服务调用。有没有办法将数组或文件列表发送到控制器?

下面是代码片段:

<div data-flow-object="testModel.documentsFlowObject"
                 data-flow-files-submitted="testModel.validateAndUpload($files, $event, $flow)"
                 data-flow-file-success="testModel.documentUploadSuccess($file, $message, $flow)"
                 data-flow-file-error="testModel.documentUploadError($file, $message, $flow)"
                 data-flow-init>

function validateAndUpload(files,$event,flow)
        {
            checkAllFiles(files); // Few validations
            for(var file in files)
            {
            // Flag is set based on validation
                var fileName = formatFileName(files[file].name);
                if(checkFileNames(fileName)===false)
                {                  
                    testModel.uploadFlag=false;
                    break;
                }
                else
                {
                    setDocumentUploadPath();
                    testModel.uploadFlag = true;
                }
            }
            if(testModel.uploadFlag===false )
            {
                $event.preventDefault();
                resetDocumentsUpload(files, $event, flow);
            }
            else
            {
                LoadingModalService.open();
                flow.upload();
            }
        
        }

MVC 控制器:

@RequestMapping(value = "/documents/{id}", method = POST)
        public ResponseEntity<?> uploadDocument(@PathVariable String id, @RequestParam("docIds") List<String> docIds, @RequestParam("file") MultipartFile file) {

有没有办法通过 ng-flow 在请求中获取 List 或 MultipartFile[]?

4

0 回答 0