当前位置: 首页>>代码示例>>Java>>正文


Java MultipartHttpServletRequest.getMultiFileMap方法代码示例

本文整理汇总了Java中org.springframework.web.multipart.MultipartHttpServletRequest.getMultiFileMap方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartHttpServletRequest.getMultiFileMap方法的具体用法?Java MultipartHttpServletRequest.getMultiFileMap怎么用?Java MultipartHttpServletRequest.getMultiFileMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.multipart.MultipartHttpServletRequest的用法示例。


在下文中一共展示了MultipartHttpServletRequest.getMultiFileMap方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Upload

import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
@RequestMapping(value = "Upload")
public String Upload(HttpServletRequest request) throws Exception {
    // ת��ΪMultipartHttpRequest
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    // ����ϴ����ļ�������ǰ̨��name���Ƶõ��ϴ����ļ���
    MultiValueMap<String, MultipartFile> multiValueMap = multipartRequest.getMultiFileMap();
    List<MultipartFile> files = multiValueMap.get("clientFile");
    //MultipartFile file = multipartRequest.getFile("clientFile");
    if (!files.isEmpty()) {
        //������Ϳ��Զ�file���д����ˣ����Ը����Լ�����������浽���ݿ���߷�������ij���ļ���
    /*for(MultipartFile file :files)
     {
         fileService.upload(file);
     }*/
        //ʹ��forEach ��Lambda ʵ��
        files.forEach(f -> fileService.upload(f));
    }
    return "Success";
}
 
开发者ID:nizhaorong,项目名称:S4S4H4,代码行数:20,代码来源:FileController.java

示例2: handle

import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
public void handle(HttpServletRequest request) {
    if (request instanceof MultipartHttpServletRequest) {
        logger.debug("force cast to MultipartHttpServletRequest");

        MultipartHttpServletRequest req = (MultipartHttpServletRequest) request;
        this.multiFileMap = req.getMultiFileMap();
        logger.debug("multiFileMap : {}", multiFileMap);
        this.handleMultiValueMap(req);
        logger.debug("multiValueMap : {}", multiValueMap);

        return;
    }

    if (multipartResolver.isMultipart(request)) {
        logger.debug("is multipart : {}",
                multipartResolver.isMultipart(request));
        this.multipartHttpServletRequest = multipartResolver
                .resolveMultipart(request);

        logger.debug("multipartHttpServletRequest : {}",
                multipartHttpServletRequest);
        this.multiFileMap = multipartHttpServletRequest.getMultiFileMap();
        logger.debug("multiFileMap : {}", multiFileMap);
        this.handleMultiValueMap(multipartHttpServletRequest);
        logger.debug("multiValueMap : {}", multiValueMap);
    } else {
        this.handleMultiValueMap(request);
        logger.debug("multiValueMap : {}", multiValueMap);
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:31,代码来源:MultipartHandler.java

示例3: doPost

import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
  // Check that we have a file upload request
  boolean isMultipart = ServletFileUpload.isMultipartContent(request);
  if (!isMultipart) {
    return;
  }
  try {
    MultipartHttpServletRequest
        multiRequest =
        new CommonsMultipartResolver().resolveMultipart(request);
    MultiValueMap<String, MultipartFile> fileMap = multiRequest.getMultiFileMap();
    BlobstoreService blobstoreService = AppFactory.get().getBlobstoreService();
    Map<String, String> names = new HashMap<>(1);
    for (String fieldName : fileMap.keySet()) {
      MultipartFile file = fileMap.getFirst(fieldName);
      String fileName = file.getOriginalFilename();
      String contentType = file.getContentType();
      long sizeInBytes = file.getSize();
      String
          blobKey =
          blobstoreService.store(fileName, contentType, sizeInBytes, file.getInputStream());
      names.put(fieldName, blobKey);

    }
    request.getSession().setAttribute("blobs", names);
    RequestDispatcher
        dispatcher =
        getServletContext().getRequestDispatcher(request.getParameter("ru"));
    dispatcher.forward(multiRequest, response);
  } catch (Exception ex) {
    _logger.severe("Upload failed", ex);
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:35,代码来源:FileUploadServlet.java

示例4: doPost

import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
  // Check that we have a file upload request
  boolean isMultipart = ServletFileUpload.isMultipartContent(request);
  if (!isMultipart) {
    return;
  }
  try {
    MultipartHttpServletRequest
        multiRequest =
        new CommonsMultipartResolver().resolveMultipart(request);
    MultiValueMap<String, MultipartFile> fileMap = multiRequest.getMultiFileMap();
    BlobstoreService blobstoreService = AppFactory.get().getBlobstoreService();
    Map<String, String> names = new HashMap<>(1);
    for (String fieldName : fileMap.keySet()) {
      MultipartFile file = fileMap.getFirst(fieldName);
      String fileName = file.getOriginalFilename();
      String contentType = file.getContentType();
      long sizeInBytes = file.getSize();
      String
          blobKey =
          blobstoreService.store(fileName, contentType, sizeInBytes, file.getInputStream());
      names.put(fieldName, blobKey);
      names.put("file", fileName);

    }
    response.getWriter().write(new Gson().toJson(names));
    response.setStatus(HttpStatus.SC_CREATED);
  } catch (Exception ex) {
    _logger.severe("Upload failed", ex);
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:33,代码来源:DirectFileUploadServlet.java

示例5: doTestFiles

import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
private void doTestFiles(MultipartHttpServletRequest request) throws IOException {
	Set<String> fileNames = new HashSet<String>();
	Iterator<String> fileIter = request.getFileNames();
	while (fileIter.hasNext()) {
		fileNames.add(fileIter.next());
	}
	assertEquals(3, fileNames.size());
	assertTrue(fileNames.contains("field1"));
	assertTrue(fileNames.contains("field2"));
	assertTrue(fileNames.contains("field2x"));
	CommonsMultipartFile file1 = (CommonsMultipartFile) request.getFile("field1");
	CommonsMultipartFile file2 = (CommonsMultipartFile) request.getFile("field2");
	CommonsMultipartFile file2x = (CommonsMultipartFile) request.getFile("field2x");

	Map<String, MultipartFile> fileMap = request.getFileMap();
	assertEquals(3, fileMap.size());
	assertTrue(fileMap.containsKey("field1"));
	assertTrue(fileMap.containsKey("field2"));
	assertTrue(fileMap.containsKey("field2x"));
	assertEquals(file1, fileMap.get("field1"));
	assertEquals(file2, fileMap.get("field2"));
	assertEquals(file2x, fileMap.get("field2x"));

	MultiValueMap<String, MultipartFile> multiFileMap = request.getMultiFileMap();
	assertEquals(3, multiFileMap.size());
	assertTrue(multiFileMap.containsKey("field1"));
	assertTrue(multiFileMap.containsKey("field2"));
	assertTrue(multiFileMap.containsKey("field2x"));
	List<MultipartFile> field1Files = multiFileMap.get("field1");
	assertEquals(2, field1Files.size());
	assertTrue(field1Files.contains(file1));
	assertEquals(file1, multiFileMap.getFirst("field1"));
	assertEquals(file2, multiFileMap.getFirst("field2"));
	assertEquals(file2x, multiFileMap.getFirst("field2x"));

	assertEquals("type1", file1.getContentType());
	assertEquals("type2", file2.getContentType());
	assertEquals("type2", file2x.getContentType());
	assertEquals("field1.txt", file1.getOriginalFilename());
	assertEquals("field2.txt", file2.getOriginalFilename());
	assertEquals("field2x.txt", file2x.getOriginalFilename());
	assertEquals("text1", new String(file1.getBytes()));
	assertEquals("text2", new String(file2.getBytes()));
	assertEquals(5, file1.getSize());
	assertEquals(5, file2.getSize());
	assertTrue(file1.getInputStream() instanceof ByteArrayInputStream);
	assertTrue(file2.getInputStream() instanceof ByteArrayInputStream);
	File transfer1 = new File("C:/transfer1");
	file1.transferTo(transfer1);
	File transfer2 = new File("C:/transfer2");
	file2.transferTo(transfer2);
	assertEquals(transfer1, ((MockFileItem) file1.getFileItem()).writtenFile);
	assertEquals(transfer2, ((MockFileItem) file2.getFileItem()).writtenFile);

}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:56,代码来源:CommonsMultipartResolverTests.java


注:本文中的org.springframework.web.multipart.MultipartHttpServletRequest.getMultiFileMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。