Browse Source

汽车之家上传文件脚本

dengsixing 3 years ago
parent
commit
fdbf07c241

+ 30 - 4
4dkankan-utils-fyun/src/main/java/com/fdkankan/fyun/oss/UploadToOssUtil.java

@@ -92,12 +92,20 @@ public class UploadToOssUtil {
 	private String localPath;
 	private String localPath;
 
 
 	/**
 	/**
-	 * oss文件上传命令
+	 * 上传目录到oss
 	 * 第1个参数是本地文件路径
 	 * 第1个参数是本地文件路径
 	 * 第2个参数是oss路径
 	 * 第2个参数是oss路径
 	 * 第3个参数是bucket名
 	 * 第3个参数是bucket名
 	 */
 	 */
-	private static final String UPLOAD_SH = "bash /opt/ossutil/upload.sh %s %s %s";
+	private static final String UPLOAD_DIR_SH = "bash /opt/ossutil/upload.sh %s %s %s";
+
+	/**
+	 * 上传单个文件到oss
+	 * 第1个参数是本地文件路径
+	 * 第2个参数是oss路径
+	 * 第3个参数是bucket名
+	 */
+	private static final String UPLOAD_FFILE_SH = "bash /opt/ossutil/upload-file.sh %s %s %s";
 
 
 	//上传的数据是byte[],key是上传后的文件名
 	//上传的数据是byte[],key是上传后的文件名
 	public void upload(byte[] data,String key1) throws IOException{
 	public void upload(byte[] data,String key1) throws IOException{
@@ -136,9 +144,9 @@ public class UploadToOssUtil {
 	 * @param filePath
 	 * @param filePath
 	 * @param key
 	 * @param key
 	 */
 	 */
-	public void uploadBySh(String bucket, String filePath, String key) {
+	public void uploadDirBySh(String bucket, String filePath, String key) {
 		try {
 		try {
-			String command = String.format(UploadToOssUtil.UPLOAD_SH, filePath, key, bucket);
+			String command = String.format(UploadToOssUtil.UPLOAD_DIR_SH, filePath, key, bucket);
 			log.info("开始上传文件, ossPath:{}, srcPath:{}", key, filePath);
 			log.info("开始上传文件, ossPath:{}, srcPath:{}", key, filePath);
 			CreateObjUtil.callshell(command);
 			CreateObjUtil.callshell(command);
 			log.info("上传文件完毕, ossPath:{}, srcPath:{}", key, filePath);
 			log.info("上传文件完毕, ossPath:{}, srcPath:{}", key, filePath);
@@ -148,6 +156,24 @@ public class UploadToOssUtil {
 		}
 		}
 	}
 	}
 
 
+	/**
+	 * 通过脚本上传单个文件
+	 * @param filePath
+	 * @param key
+	 */
+	public void uploadFileBySh(String bucket, String filePath, String key) {
+		try {
+			String command = String.format(UploadToOssUtil.UPLOAD_FFILE_SH, filePath, key, bucket);
+			log.info("开始上传文件, ossPath:{}, srcPath:{}", key, filePath);
+			CreateObjUtil.callshell(command);
+			log.info("上传文件完毕, ossPath:{}, srcPath:{}", key, filePath);
+		} catch(Exception e) {
+			log.error("上传文件失败, ossPath:{}, srcPath:{}", key, filePath);
+			log.error("上传文件失败", e);
+		}
+	}
+
+
 	public void uploadSdk(String filePath, String key1) {
 	public void uploadSdk(String filePath, String key1) {
 		log.info("开始上传文件 源路径:{},目标路径:{},type:{}" , filePath,key1,type);
 		log.info("开始上传文件 源路径:{},目标路径:{},type:{}" , filePath,key1,type);
 		switch (type){
 		switch (type){