[英]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.