尝试在Spring中上传文件时为[空]

时间:2018-11-02 18:24:49

标签: spring-boot

尝试使用此REST调用上传文件,但找到空数组

**Spring**:
//Multi file upload
    @RequestMapping(value = "/api/upload/multipart", method = RequestMethod.POST,consumes = { "multipart/form-data" } )
    // If not @RestController, uncomment this
    @ResponseBody
    public ResponseEntity<?> uploadFile(
      @RequestParam("file") MultipartFile[] uploadfileList, @RequestParam("fileType") String  fileType) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException {

        logger.debug("Multiple file upload!");

        MultipartFile uploadfileimage;

        List<FileUpload> fileuploadList = new ArrayList<>();
        for (int i = 0; i < uploadfileList.length ; i++) {
            uploadfileimage = uploadfileList[i];
              FileUpload fileUpload = new FileUpload();
              fileUpload.setFileName(uploadfileimage.getOriginalFilename());
              fileUpload.setData(uploadfileimage.getBytes());
              fileUpload.setFileType(fileType);
              fileuploadList.add(fileUpload);
        }
        fileuploadList = (List<FileUpload>) 
         fileUploadRepository.saveAll(fileuploadList);
        return new ResponseEntity("Successfully uploaded - " +
                fileuploadList, new HttpHeaders(), HttpStatus.OK);

    }

客户代码 他们在客户端没有问题。成功发送数据 enter image description here

enter image description here

可能为空[]的原因是什么?任何帮助将不胜感激。

0 个答案:

没有答案