繁体   English   中英

使用MultiPart上传图像

[英]image uploading using MultiPart

我正在编写代码以使用服务器上的Spring的MultipartFile上传文件,因为我已经编写了以下代码

if(!partnersContentBean.getFile().isEmpty()){
        MultipartFile file = partnersContentBean.getFile();

    if(file.getOriginalFilename().endsWith(".jpeg")||file.getOriginalFilename().endsWith(".jpg")|| file.getOriginalFilename().endsWith(".gif")){
        File dirPath = new File("//125.22.60.37/image/dev/cmt/");
       if (!dirPath.exists()) {
               dirPath.mkdirs();
       } 
        URL url = new URL("http://125.22.60.37/image/dev/cmt/"); 
           File destination = new File(url.toString());
           file.transferTo(destination);
           String url1 = request.getContextPath() + ApplicationConstants.imageUploadDirectory + file.getOriginalFilename();
           System.out.println(url.getPath());
           partnersContentBean.setPartnerImagename(file.getOriginalFilename());
           partnersContentBean.setPartnerImagepath(destination.getPath());


        }else
        {
            userModuleDetailBean.put("errorMessage", "File should be in type of jpg,Jpeg or GIF");
            return new ModelAndView(new RedirectView("partnersAdd_CMT.htm"),"userModuleDetailBean",userModuleDetailBean);
        }
     } 

但是当我上传文件时,出现以下异常java.io.FileNotFoundException: http:\\125.22.60.37\\image\\dev\\cmt (The filename, directory name, or volume label syntax is incorrect)不知道我应该给哪个路径上载

您似乎正在尝试将上传的文件传输到另一台远程服务器( 125.22.60.37 )。 您不能这样做-您不能使用File对象表示HTTP URL。

FileUpload用于将上传的文件存储到本地计算机。 到达那里后,您可以担心将它们移至另一台远程服务器,但这两个任务是分开的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM