MultipartFile File Determines Existence

  • 2021-10-15 10:42:40
  • OfStack

The MultipartFile file determines whether it exists

MultipartFile Most of the time, even if you do not upload files, there will still be data, but the stream data is empty. If you want to judge the empty MultipartFile file, you can use API that comes with MultipartFile


MultipartFile file = new CommonsMultipartFile(null);
file.isEmpty()

If true is returned, it is empty

MultipartFile How to Judge Nulls When Accepting Files


@RequestParam MultipartFile file

Incorrect usage:


if (null != file) {
System.out.println(" This is always true !");
}

Correct usage:


if (StringUtils.isNotBlank(file.getOriginalFilename())) {
System.out.println(" It should be judged by getting the file name. ");
}

Related articles: