AliOssBackup.java
1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.jflyfox.system.file.service.impl;
import java.io.File;
import com.jflyfox.system.file.model.FileUploadBean;
import com.jflyfox.system.file.service.IFileBackup;
import com.jflyfox.system.file.util.AliyunOSSUtils;
import com.jflyfox.system.file.util.FileUploadUtils;
/**
* 阿里云OSS备份
*
* 2017年4月5日 上午3:07:28 flyfox 369191470@qq.com
*/
public class AliOssBackup implements IFileBackup {
private AliyunOSSUtils ossUtils = new AliyunOSSUtils();
public boolean backup(FileUploadBean fileBean) {
String srcPath = (fileBean.getPath().startsWith("/") ? fileBean.getPath().substring(1) : fileBean.getPath());
ossUtils.uploadFile(srcPath, fileBean.getFactpath());
return true;
}
public boolean restore(String projectPath) {
String srcPath = (projectPath.startsWith("/") ? "" : "/") + projectPath;
String webRootPath = FileUploadUtils.getRootPath(); // 项目路径
String projectFactPath = FileUploadUtils.rebuild(webRootPath + srcPath);
File destFile = new File(projectFactPath);
if (destFile.exists()) {
return true;
}
ossUtils.downloadFile(projectPath, projectFactPath);
return true;
}
}