java 上传文件到服务器_ameqp服务器网址Java中@

private String saveImageReturnPathMultipartFile multiFile) throws IllegalStateException, IOException { 
   
		
		String dateName = PicFileUtil.randomFileName)+multiFile.getOriginalFilename);
		
        String path = PicFileUtil.getImgUploadPathConstants.UPLOAD_NAME); // /upload

        String fileName = String.format"%s/%s", PicFileUtil.dateFolder), dateName);

        String filePathName = String.format"/%s/%s", Constants.UPLOAD_NAME, fileName);
        
        String filePath = String.format"/%s/%s", path, fileName);

        File file = new FilefilePath);
        if !file.getParentFile).exists)) { 
   
            file.getParentFile).mkdirs);
        }
        multiFile.transferTofile);
        return filePathName;
    }
	// 上传文件

	@Override
	public String uploadFileMultipartFile file) { 
   
			
		try { 
   
			return "/ba/"+saveImageReturnPathfile);
		} catch Exception e) { 
   
			e.printStackTrace);
		}
		return null;
		
	}
}

文件上传地址:

public static String getImgUploadPathString folderName) { 
   
		
		// /home/yishang_data/project/lib/yishang_data_main.jar!/BOOT-INF/classes!/../../upload
		String path = ClassUtils.getDefaultClassLoader).getResource"").getPath) + "../../../../" + folderName;
		path = path.replace"file:", "");
		
		log.info"path={}", path);
		
		File file = new Filepath);
		if ! file.exists) ) { 
   
			file.mkdirs);
		}
		path = getRealPathpath);
		return path;
	}

关注公众号【程序员每日一学】让我们每天一起进步~

在这里插入图片描述在这里插入图片描述

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注