首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >上载多个文件,enctype=“多部分/表单-数据”

上载多个文件,enctype=“多部分/表单-数据”
EN

Stack Overflow用户
提问于 2015-04-30 22:08:30
回答 1查看 968关注 0票数 1

我想上传多个文件到控制器,但它只需要一个。

我正在使用多部分文件传输。如何将多个文件送到控制器端。我无法访问字节和文件名。它的投掷错误,

代码语言:javascript
复制
@RequestMapping(value = "/home/step38/uploadReport", method = RequestMethod.POST)
public ModelAndView uploadReport(                 
         @RequestParam(value = "fileName") List<MultipartFile> files,
         @RequestParam(value = "pLogId") String pLogId,
          HttpServletRequest request, HttpSession session) 
{ 
    int applicationNameId = 0;
   String fileName;
    String typeOption = "Raw Particle Data";
    for(MultipartFile file:files)      
     fileName = file.getOriginalFilename();

    logger.debug("step3.1 upload particle count -- Start");

    ModelAndView modelAndView = createModelAndView(ToogleStep.step38);
    setCurrentStep(session, modelAndView, ToogleStep.step38);
    String view = "redirect:/home/step38";
    modelAndView.setViewName(view);   

    try 
    {
        User user = (User) session.getAttribute(Constants.USER_DB);
        Project current_project = (Project) session.getAttribute(Constants.PROJECT);
        Credential credential = (Credential) session.getAttribute(Constants.AUTH_USER);            
        boolean checkOK = true;        

        if (current_project != null && SystemUtils.projectEditable(current_project, credential)) 
        {
            long projectId = current_project.getId();

            if(checkOK)
            {
               byte[] bytes = file.getBytes();      
                HashMap<String,String> options= new HashMap<String,String>();
               //added pLogId in the options(this will contain demoToogleFileInfoId)           
                options.put(ToogleReportDataConstants.TTL_PROCESS_LOG_ID_OPTION,pLogId);
                String toogleFileId = reportService.uploadReport(user, projectId, fileName, typeOption, bytes, applicationNameId, options);

            }
        }         
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-07 22:46:48

你没有在正确的位置循环通过。在你有你的modelAndView(视图)之后尝试循环它

代码语言:javascript
复制
 int applicationNameId = 0;
        String typeOption = "Raw Particle Data";
        ModelAndView modelAndView = createModelAndView(ToogleStep.step38);
        setCurrentStep(session, modelAndView, ToogleStep.step38);
        String view = "redirect:/home/step38";
        modelAndView.setViewName(view);   

        // upload multiple files.       
          for(MultipartFile file:files){   
            String fileName= file.getOriginalFilename();

然后您将能够访问字节和文件名。试试看。至少,看看你的问题,我可以建议,如果你能给出更具体的错误,我可以帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29978679

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档