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

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

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

MultipartFile.getName介绍

[英]Return the name of the parameter in the multipart form.
[中]以多部分形式返回参数的名称。

代码示例

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

/**
 * This implementation returns a description that has the Multipart name.
 */
@Override
public String getDescription() {
  return "MultipartFile resource [" + this.multipartFile.getName() + "]";
}

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

/**
 * Add a file to this request. The parameter name from the multipart
 * form is taken from the {@link MultipartFile#getName()}.
 * @param file multipart file to be added
 */
public void addFile(MultipartFile file) {
  Assert.notNull(file, "MultipartFile must not be null");
  this.multipartFiles.add(file.getName(), file);
}

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

/**
 * This implementation returns a description that has the Multipart name.
 */
@Override
public String getDescription() {
  return "MultipartFile resource [" + this.multipartFile.getName() + "]";
}

代码示例来源:origin: gocd/gocd

private boolean shouldUnzipStream(MultipartFile multipartFile) {
  return multipartFile.getName().equals(ZIP_MULTIPART_FILENAME);
}

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

/**
 * Add a file to this request. The parameter name from the multipart
 * form is taken from the {@link MultipartFile#getName()}.
 * @param file multipart file to be added
 */
public void addFile(MultipartFile file) {
  Assert.notNull(file, "MultipartFile must not be null");
  this.multipartFiles.add(file.getName(), file);
}

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

params.append("  ").append(paramNames.get(i)).append(": ").append(file.getName());
} else {
  params.append("  ").append(paramNames.get(i)).append(": ").append(args[i]);

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

private void doTestMultipartHttpServletRequest(MultipartHttpServletRequest request) throws IOException {
  Set<String> fileNames = new HashSet<>();
  Iterator<String> fileIter = request.getFileNames();
  while (fileIter.hasNext()) {
    fileNames.add(fileIter.next());
  }
  assertEquals(2, fileNames.size());
  assertTrue(fileNames.contains("file1"));
  assertTrue(fileNames.contains("file2"));
  MultipartFile file1 = request.getFile("file1");
  MultipartFile file2 = request.getFile("file2");
  Map<String, MultipartFile> fileMap = request.getFileMap();
  List<String> fileMapKeys = new LinkedList<>(fileMap.keySet());
  assertEquals(2, fileMapKeys.size());
  assertEquals(file1, fileMap.get("file1"));
  assertEquals(file2, fileMap.get("file2"));
  assertEquals("file1", file1.getName());
  assertEquals("", file1.getOriginalFilename());
  assertNull(file1.getContentType());
  assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), file1.getBytes()));
  assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(),
    FileCopyUtils.copyToByteArray(file1.getInputStream())));
  assertEquals("file2", file2.getName());
  assertEquals("myOrigFilename", file2.getOriginalFilename());
  assertEquals("text/plain", file2.getContentType());
  assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), file2.getBytes()));
  assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(),
    FileCopyUtils.copyToByteArray(file2.getInputStream())));
}

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

@Override
public MultipartFile readMultipartFile(MultipartFile multipartFile) throws IOException {
  File upload = File.createTempFile(this.prefix, this.suffix, this.directory);
  multipartFile.transferTo(upload);
  UploadedMultipartFile uploadedMultipartFile = new UploadedMultipartFile(upload, multipartFile.getSize(),
      multipartFile.getContentType(), multipartFile.getName(), multipartFile.getOriginalFilename());
  if (logger.isDebugEnabled()) {
    logger.debug("copied uploaded file [" + multipartFile.getOriginalFilename() +
        "] to [" + upload.getAbsolutePath() + "]");
  }
  return uploadedMultipartFile;
}

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

private OperationRequestPart createOperationRequestPart(MultipartFile file)
    throws IOException {
  HttpHeaders partHeaders = new HttpHeaders();
  if (StringUtils.hasText(file.getContentType())) {
    partHeaders.setContentType(MediaType.parseMediaType(file.getContentType()));
  }
  return new OperationRequestPartFactory().create(file.getName(),
      StringUtils.hasText(file.getOriginalFilename())
          ? file.getOriginalFilename() : null,
      file.getBytes(), partHeaders);
}

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

public MultipartFile readMultipartFile(MultipartFile multipartFile) throws IOException {
  return new UploadedMultipartFile(multipartFile.getBytes(),
      multipartFile.getContentType(), multipartFile.getName(), multipartFile.getOriginalFilename());
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web

/**
 * This implementation returns a description that has the Multipart name.
 */
@Override
public String getDescription() {
  return "MultipartFile resource [" + this.multipartFile.getName() + "]";
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Add a file to this request. The parameter name from the multipart
 * form is taken from the {@link MultipartFile#getName()}.
 * @param file multipart file to be added
 */
public void addFile(MultipartFile file) {
  Assert.notNull(file, "MultipartFile must not be null");
  this.multipartFiles.add(file.getName(), file);
}

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

@PostMapping("/{id}/file")
  @ApiOperation(value = "文件上传(DONE)")
  public String file(@PathVariable Long id, @RequestParam("file") MultipartFile file) {
    log.info(file.getContentType());
    log.info(file.getName());
    log.info(file.getOriginalFilename());
    return file.getOriginalFilename();
  }
}

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

@PostMapping("/{id}/file")
  @ApiOperation(value = "文件上传(DONE)")
  public String file(@PathVariable Long id, @RequestParam("file") MultipartFile file) {
    log.info(file.getContentType());
    log.info(file.getName());
    log.info(file.getOriginalFilename());
    return file.getOriginalFilename();
  }
}

代码示例来源:origin: stackoverflow.com

for (MultipartFile multipartFile : files) {
   System.out.println(multipartFile.getOriginalFilename()+"       "+multipartFile.getContentType()+" "+multipartFile.getName());
   try {
       multipartFile.transferTo(new File(filePathToSave+"/"+multipartFile.getOriginalFilename()));
   } catch (IllegalStateException | IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
   }
 }

代码示例来源:origin: io.github.openfeign.form/feign-form-spring

@Override
 public void encode (Object object, Type bodyType, RequestTemplate template) throws EncodeException {
  if (!bodyType.equals(MultipartFile.class)) {
   super.encode(object, bodyType, template);
   return;
  }

  val file = (MultipartFile) object;
  val data = singletonMap(file.getName(), object);
  super.encode(data, MAP_STRING_WILDCARD, template);
 }
}

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

@Override
public MultipartFile readMultipartFile(MultipartFile multipartFile) throws IOException {
  File upload = File.createTempFile(this.prefix, this.suffix, this.directory);
  multipartFile.transferTo(upload);
  UploadedMultipartFile uploadedMultipartFile = new UploadedMultipartFile(upload, multipartFile.getSize(),
      multipartFile.getContentType(), multipartFile.getName(), multipartFile.getOriginalFilename());
  if (logger.isDebugEnabled()) {
    logger.debug("copied uploaded file [" + multipartFile.getOriginalFilename() +
        "] to [" + upload.getAbsolutePath() + "]");
  }
  return uploadedMultipartFile;
}

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

private OperationRequestPart createOperationRequestPart(MultipartFile file)
    throws IOException {
  HttpHeaders partHeaders = new HttpHeaders();
  if (StringUtils.hasText(file.getContentType())) {
    partHeaders.setContentType(MediaType.parseMediaType(file.getContentType()));
  }
  return new OperationRequestPartFactory().create(file.getName(),
      StringUtils.hasText(file.getOriginalFilename())
          ? file.getOriginalFilename() : null,
      file.getBytes(), partHeaders);
}

代码示例来源:origin: com.gitee.zhaohuihua/bdp-general-web

public static InputData getInputData(MultipartFile file) throws ServiceException {
  if (file == null || file.getSize() == 0 || VerifyTools.isBlank(file.getName())) {
    return null;
  }
  try {
    return new InputData(file.getOriginalFilename(), file.getInputStream(), file.getSize());
  } catch (IOException e) {
    throw new ServiceException(ResultCode.SERVER_INNER_ERROR, e);
  }
}

代码示例来源:origin: codeabovelab/haven-platform

@RequestMapping(value = "clusters/{cluster}/compose", method = POST, consumes = {MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<ComposeResult> deployClusterFromCompose(@PathVariable("cluster") String cluster,
                               @RequestPart(value = "data") MultipartFile multipartFile) throws Exception {
  //String root, String cluster, String app, String fileName
  File file = ComposeUtils.clusterPath(composeExecutor.getBasedir(), cluster, multipartFile.getName());
  Files.write(multipartFile.getBytes(), file);
  DockerService service = discoveryStorage.getService(cluster);
  ComposeResult composeResult = composeExecutor.up(ComposeArg.builder().file(file).build(), service);
  log.info("result of executing compose: {}", composeResult);
  createApplications(composeResult, cluster);
  return new ResponseEntity<>(composeResult, UiUtils.toStatus(composeResult.getResultCode()));
}

相关文章