开发者

image uploading using MultiPart

I am writting the code to upload a file using Spring's MultipartFile on server for that I have written following code

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 M开发者_如何学编程odelAndView(new RedirectView("partnersAdd_CMT.htm"),"userModuleDetailBean",userModuleDetailBean);
        }
     } 

but when I upload a file I get following exception java.io.FileNotFoundException: http:\125.22.60.37\image\dev\cmt (The filename, directory name, or volume label syntax is incorrect) dont know what path should i give to upload it


It looks like you're trying to transfer the uploaded file to another remote server (125.22.60.37). You can't do that - you can't represent an HTTP URL using a File object.

FileUpload is for storing the uploaded files to your local machine. Once there, you can worry about moving them to another remote server, but the two tasks are separate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜