views:

94

answers:

1

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 ModelAndView(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

A: 

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.

skaffman
k then how can I do that
Vipul
i mean is there any way to do this shal I move manually transfer those file using anothe client like ssh etc. or any other way
Vipul
@Vipul: That depends on your setup. I suggest you close this question, and open another one which is not related to file upload.
skaffman