上传

public UploadVo upload(MultipartFile file) throws Exception {
        UploadVo uploadVo = new UploadVo();
        if (!file.isEmpty()) {
            String fileName = file.getOriginalFilename();
            String fileType = fileName.substring(fileName.lastIndexOf(".")+1);
            long fileSize = file.getSize();
            String Path = "D:\\javaspace\\tomcatPath";
            File packageFile = new File(Path);
            if (!packageFile.exists()) {
                packageFile.mkdir();
            }
            File targetFile = new File(Path + "\\" + fileName);
            file.transferTo(targetFile);
            uploadVo.setBeginFileName(fileName);
            uploadVo.setLastFileName(fileName);
            uploadVo.setFileSize(String.valueOf(fileSize));
            uploadVo.setResult("上传成功");
            return uploadVo;
        } else {
            uploadVo.setResult(String.valueOf(ErrorMessageConstant.ERROR_CODE_10004));
            return uploadVo;
        }
    }

  

posted @ 2018-10-15 12:07  冷枚  阅读(155)  评论(0编辑  收藏  举报