|
@@ -27,9 +27,10 @@ public class OssFileService extends AbstractFYunFileService {
|
|
|
private OSS ossClient;
|
|
|
|
|
|
@Override
|
|
|
- public void uploadFile(String bucket, byte[] data, String remoteFilePath) {
|
|
|
+ public String uploadFile(String bucket, byte[] data, String remoteFilePath) {
|
|
|
try {
|
|
|
ossClient.putObject(bucket, remoteFilePath, new ByteArrayInputStream(data));
|
|
|
+ return fYunFileConfig.getHost().concat(remoteFilePath);
|
|
|
} catch (Exception e) {
|
|
|
log.error("oss上传文件失败", e);
|
|
|
e.printStackTrace();
|
|
@@ -38,24 +39,25 @@ public class OssFileService extends AbstractFYunFileService {
|
|
|
ossClient.shutdown();
|
|
|
}
|
|
|
}
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void uploadFile(String bucket, String filePath, String remoteFilePath) {
|
|
|
- uploadFile(bucket, filePath, remoteFilePath, true, null);
|
|
|
+ public String uploadFile(String bucket, String filePath, String remoteFilePath) {
|
|
|
+ return uploadFile(bucket, filePath, remoteFilePath, true, null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void uploadFile(String bucket, String filePath, String remoteFilePath, Map<String, String> headers) {
|
|
|
- uploadFile(bucket, filePath, remoteFilePath, true, headers);
|
|
|
+ public String uploadFile(String bucket, String filePath, String remoteFilePath, Map<String, String> headers) {
|
|
|
+ return uploadFile(bucket, filePath, remoteFilePath, true, headers);
|
|
|
}
|
|
|
|
|
|
- private void uploadFile(String bucket, String filePath, String remoteFilePath, Boolean shutdown,Map<String, String> headers) {
|
|
|
+ private String uploadFile(String bucket, String filePath, String remoteFilePath, Boolean shutdown,Map<String, String> headers) {
|
|
|
try {
|
|
|
File file = new File(filePath);
|
|
|
if (!file.exists()) {
|
|
|
log.error("要上传的文件不存在:" + filePath);
|
|
|
- return;
|
|
|
+ return null;
|
|
|
}
|
|
|
ObjectMetadata metadata = new ObjectMetadata();
|
|
|
if (filePath.contains(".jpg")) {
|
|
@@ -73,9 +75,11 @@ public class OssFileService extends AbstractFYunFileService {
|
|
|
}
|
|
|
}
|
|
|
ossClient.putObject(bucket, remoteFilePath, new File(filePath), metadata);
|
|
|
+ return fYunFileConfig.getHost().concat(remoteFilePath);
|
|
|
} catch (Exception e) {
|
|
|
log.error("oss上传文件失败", e);
|
|
|
e.printStackTrace();
|
|
|
+ return null;
|
|
|
} finally {
|
|
|
if ((ObjectUtils.isEmpty(shutdown) || shutdown) && !ObjectUtils.isEmpty(ossClient)) {
|
|
|
ossClient.shutdown();
|
|
@@ -84,15 +88,17 @@ public class OssFileService extends AbstractFYunFileService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void uploadFileByCommand(String bucket, String filePath, String remoteFilePath) {
|
|
|
+ public String uploadFileByCommand(String bucket, String filePath, String remoteFilePath) {
|
|
|
String ossPath = bucket + "/" + remoteFilePath;
|
|
|
try {
|
|
|
String command = String.format(OssConstants.UPLOAD_SH, ossPath, filePath);
|
|
|
log.info("开始上传文件, ossPath:{}, srcPath:{}", ossPath, filePath);
|
|
|
CreateObjUtil.callshell(command);
|
|
|
+ return fYunFileConfig.getHost().concat(remoteFilePath);
|
|
|
} catch (Exception e) {
|
|
|
log.error("上传文件失败, ossPath:{}, srcPath:{}", ossPath, filePath);
|
|
|
e.printStackTrace();
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|