org.springframework.web.multipart.MultipartFile.isEmpty()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(364)

本文整理了Java中org.springframework.web.multipart.MultipartFile.isEmpty()方法的一些代码示例,展示了MultipartFile.isEmpty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MultipartFile.isEmpty()方法的具体详情如下:
包路径:org.springframework.web.multipart.MultipartFile
类名称:MultipartFile
方法名:isEmpty

MultipartFile.isEmpty介绍

[英]Return whether the uploaded file is empty, that is, either no file has been chosen in the multipart form or the chosen file has no content.
[中]返回上传的文件是否为空,也就是说,在多部分表单中没有选择任何文件,或者选择的文件没有内容。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Bind all multipart files contained in the given request, if any
 * (in case of a multipart request). To be called by subclasses.
 * <p>Multipart files will only be added to the property values if they
 * are not empty or if we're configured to bind empty multipart files too.
 * @param multipartFiles a Map of field name String to MultipartFile object
 * @param mpvs the property values to be bound (can be modified)
 * @see org.springframework.web.multipart.MultipartFile
 * @see #setBindEmptyMultipartFiles
 */
protected void bindMultipart(Map<String, List<MultipartFile>> multipartFiles, MutablePropertyValues mpvs) {
  multipartFiles.forEach((key, values) -> {
    if (values.size() == 1) {
      MultipartFile value = values.get(0);
      if (isBindEmptyMultipartFiles() || !value.isEmpty()) {
        mpvs.add(key, value);
      }
    }
    else {
      mpvs.add(key, values);
    }
  });
}

代码示例来源:origin: ityouknow/spring-boot-examples

@PostMapping("/upload") // //new annotation since 4.3
public String singleFileUpload(@RequestParam("file") MultipartFile file,
                RedirectAttributes redirectAttributes) {
  if (file.isEmpty()) {
    redirectAttributes.addFlashAttribute("message", "Please select a file to upload");
    return "redirect:uploadStatus";
  }
  try {
    // Get the file and save it somewhere
    byte[] bytes = file.getBytes();
    Path path = Paths.get(UPLOADED_FOLDER + file.getOriginalFilename());
    Files.write(path, bytes);
    redirectAttributes.addFlashAttribute("message",
        "You successfully uploaded '" + file.getOriginalFilename() + "'");
  } catch (IOException e) {
    e.printStackTrace();
  }
  return "redirect:/uploadStatus";
}

代码示例来源:origin: forezp/SpringBootLearning

@Override
public void store(MultipartFile file) {
  try {
    if (file.isEmpty()) {
      throw new StorageException("Failed to store empty file " + file.getOriginalFilename());
    }
    Files.copy(file.getInputStream(), this.rootLocation.resolve(file.getOriginalFilename()));
  } catch (IOException e) {
    throw new StorageException("Failed to store file " + file.getOriginalFilename(), e);
  }
}

代码示例来源:origin: hs-web/hsweb-framework

@PostMapping(value = "/upload-static")
@ApiOperation(value = "上传静态文件", notes = "上传后响应结果的result字段为文件的访问地址")
@Authorize(action = "static", description = "上传静态文件")
public ResponseMessage<String> uploadStatic(@RequestPart("file") MultipartFile file) throws IOException {
  if (file.isEmpty()) {
    return ResponseMessage.ok();
  }
  return ResponseMessage.ok(fileService.saveStaticFile(file.getInputStream(), file.getOriginalFilename()));
}

代码示例来源:origin: roncoo/spring-boot-demo

@RequestMapping(value = "upload")
@ResponseBody
public String upload(@RequestParam("roncooFile") MultipartFile file) {
  if (file.isEmpty()) {
    return "文件为空";

代码示例来源:origin: roncoo/spring-boot-demo

@RequestMapping(value = "upload")
@ResponseBody
public String upload(@RequestParam("roncooFile") MultipartFile file) {
  if (file.isEmpty()) {
    return "文件为空";

代码示例来源:origin: roncoo/spring-boot-demo

@RequestMapping(value = "upload")
@ResponseBody
public String upload(@RequestParam("roncooFile") MultipartFile file) {
  if (file.isEmpty()) {
    return "文件为空";

代码示例来源:origin: roncoo/spring-boot-demo

@RequestMapping(value = "upload")
@ResponseBody
public String upload(@RequestParam("roncooFile") MultipartFile file) {
  if (file.isEmpty()) {
    return "文件为空";

代码示例来源:origin: roncoo/spring-boot-demo

@RequestMapping(value = "upload")
@ResponseBody
public String upload(@RequestParam("roncooFile") MultipartFile file) {
  if (file.isEmpty()) {
    return "文件为空";

代码示例来源:origin: roncoo/spring-boot-demo

@RequestMapping(value = "upload")
@ResponseBody
public String upload(@RequestParam("roncooFile") MultipartFile file) {
  if (file.isEmpty()) {
    return "文件为空";

代码示例来源:origin: roncoo/spring-boot-demo

@RequestMapping(value = "upload")
@ResponseBody
public String upload(@RequestParam("roncooFile") MultipartFile file) {
  if (file.isEmpty()) {
    return "文件为空";

代码示例来源:origin: roncoo/spring-boot-demo

@RequestMapping(value = "upload")
@ResponseBody
public String upload(@RequestParam("roncooFile") MultipartFile file) {
  if (file.isEmpty()) {
    return "文件为空";

代码示例来源:origin: roncoo/spring-boot-demo

@RequestMapping(value = "upload")
@ResponseBody
public String upload(@RequestParam("roncooFile") MultipartFile file) {
  if (file.isEmpty()) {
    return "文件为空";

代码示例来源:origin: roncoo/spring-boot-demo

@RequestMapping(value = "upload")
@ResponseBody
public String upload(@RequestParam("roncooFile") MultipartFile file) {
  if (file.isEmpty()) {
    return "文件为空";

代码示例来源:origin: roncoo/spring-boot-demo

@RequestMapping(value = "upload")
@ResponseBody
public String upload(@RequestParam("roncooFile") MultipartFile file) {
  if (file.isEmpty()) {
    return "文件为空";

代码示例来源:origin: roncoo/spring-boot-demo

@RequestMapping(value = "upload")
@ResponseBody
public String upload(@RequestParam("roncooFile") MultipartFile file) {
  if (file.isEmpty()) {
    return "文件为空";

代码示例来源:origin: org.springframework/spring-web

/**
 * Bind all multipart files contained in the given request, if any
 * (in case of a multipart request). To be called by subclasses.
 * <p>Multipart files will only be added to the property values if they
 * are not empty or if we're configured to bind empty multipart files too.
 * @param multipartFiles a Map of field name String to MultipartFile object
 * @param mpvs the property values to be bound (can be modified)
 * @see org.springframework.web.multipart.MultipartFile
 * @see #setBindEmptyMultipartFiles
 */
protected void bindMultipart(Map<String, List<MultipartFile>> multipartFiles, MutablePropertyValues mpvs) {
  multipartFiles.forEach((key, values) -> {
    if (values.size() == 1) {
      MultipartFile value = values.get(0);
      if (isBindEmptyMultipartFiles() || !value.isEmpty()) {
        mpvs.add(key, value);
      }
    }
    else {
      mpvs.add(key, values);
    }
  });
}

代码示例来源:origin: ctripcorp/apollo

@RequestParam Integer namespaceId,
 @RequestParam("file") MultipartFile file) {
if (file.isEmpty()) {
 throw new BadRequestException("The file is empty.");

代码示例来源:origin: kaaproject/kaa

/**
 * Gets the file content.
 *
 * @param file the file
 * @return the file content
 * @throws KaaAdminServiceException the kaa admin service exception
 */
protected byte[] getFileContent(MultipartFile file) throws KaaAdminServiceException {
 if (!file.isEmpty()) {
  LOG.debug("Uploading file with name '{}'", file.getOriginalFilename());
  try {
   return file.getBytes();
  } catch (IOException ex) {
   throw Utils.handleException(ex);
  }
 } else {
  LOG.error("No file found in post request!");
  throw new KaaAdminServiceException(
    "No file found in post request!",
    ServiceErrorCode.FILE_NOT_FOUND);
 }
}

代码示例来源:origin: hs-web/hsweb-framework

Authentication authentication = Authentication.current().orElse(null);
String creator = authentication == null ? null : authentication.getUser().getId();
if (file.isEmpty()) {
  return ResponseMessage.ok();

相关文章