|
@@ -27,7 +27,11 @@ public class LocalFileService extends AbstractFYunFileService {
|
|
|
|
|
|
@Override
|
|
|
public String uploadFile(String bucket, byte[] data, String remoteFilePath) {
|
|
|
- FileUtil.writeBytes(data, getOssPath(bucket, remoteFilePath));
|
|
|
+ try {
|
|
|
+ FileUtil.writeBytes(data, getOssPath(bucket, remoteFilePath));
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("oss上传文件失败,remoteFilePath:" + remoteFilePath, e);
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -38,17 +42,28 @@ public class LocalFileService extends AbstractFYunFileService {
|
|
|
|
|
|
@Override
|
|
|
public String uploadFile(String bucket, InputStream inputStream, String remoteFilePath) {
|
|
|
- FileUtil.writeFromStream(inputStream,getOssPath(bucket, remoteFilePath));
|
|
|
+ try {
|
|
|
+ FileUtil.writeFromStream(inputStream,getOssPath(bucket, remoteFilePath));
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("上传文件失败,remoteFilePath:{}", remoteFilePath);
|
|
|
+ log.error("上传文件失败", e);
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String uploadFile(String bucket, String filePath, String remoteFilePath, Map<String, String> headers) {
|
|
|
- if (!new File(filePath).exists()) {
|
|
|
- log.error("文件不存在,不予上传:{}", filePath);
|
|
|
- return null;
|
|
|
+ try {
|
|
|
+ if (!new File(filePath).exists()) {
|
|
|
+ log.warn("文件不存在:{}", filePath);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ FileUtil.copy(filePath, getOssPath(bucket, remoteFilePath), true);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("上传文件失败,filePath:{},remoteFilePath:{}", filePath, remoteFilePath);
|
|
|
+ log.error("上传文件失败", e);
|
|
|
}
|
|
|
- FileUtil.copy(filePath, getOssPath(bucket, remoteFilePath), true);
|
|
|
+
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -61,7 +76,6 @@ public class LocalFileService extends AbstractFYunFileService {
|
|
|
callshell(command);
|
|
|
} catch (Exception e) {
|
|
|
log.error("上传文件失败, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
|
- e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
@@ -75,7 +89,6 @@ public class LocalFileService extends AbstractFYunFileService {
|
|
|
callshell(command);
|
|
|
} catch (Exception e) {
|
|
|
log.error("上传文件失败, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
|
- e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -91,12 +104,8 @@ public class LocalFileService extends AbstractFYunFileService {
|
|
|
|
|
|
@Override
|
|
|
public void uploadMulFiles(String bucket, Map<String, String> filepaths) {
|
|
|
- try {
|
|
|
- for (Map.Entry<String, String> entry : filepaths.entrySet()) {
|
|
|
- uploadFile(bucket, entry.getKey(), entry.getValue(), null);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("OSS批量上传文件失败!");
|
|
|
+ for (Map.Entry<String, String> entry : filepaths.entrySet()) {
|
|
|
+ uploadFile(bucket, entry.getKey(), entry.getValue(), null);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -114,7 +123,12 @@ public class LocalFileService extends AbstractFYunFileService {
|
|
|
|
|
|
@Override
|
|
|
public void copyFileBetweenBucket(String sourceBucketName, String sourcePath, String targetBucketName, String targetPath) {
|
|
|
- FileUtil.copyContent(new File(getOssPath(sourceBucketName, sourcePath)), new File(getOssPath(targetBucketName, targetPath)), true);
|
|
|
+ try {
|
|
|
+ FileUtil.copyContent(new File(getOssPath(sourceBucketName, sourcePath)), new File(getOssPath(targetBucketName, targetPath)), true);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("复制文件失败,sourcePath:{},targetPath:{}",sourcePath,targetPath);
|
|
|
+ log.error("复制文件失败", e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -122,18 +136,20 @@ public class LocalFileService extends AbstractFYunFileService {
|
|
|
if (ObjectUtils.isEmpty(pathMap)) {
|
|
|
return;
|
|
|
}
|
|
|
- try {
|
|
|
- for (Map.Entry<String, String> entry : pathMap.entrySet()) {
|
|
|
- copyFileBetweenBucket(sourceBucketName, entry.getKey(), targetBucketName, entry.getValue());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("批量复制文件失败!");
|
|
|
+ for (Map.Entry<String, String> entry : pathMap.entrySet()) {
|
|
|
+ copyFileBetweenBucket(sourceBucketName, entry.getKey(), targetBucketName, entry.getValue());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getFileContent(String bucketName, String remoteFilePath) {
|
|
|
- return FileUtil.readUtf8String(getOssPath(bucketName, remoteFilePath));
|
|
|
+ try {
|
|
|
+ return FileUtil.readUtf8String(getOssPath(bucketName, remoteFilePath));
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("读取文件失败,remoteFilePath:{}", remoteFilePath);
|
|
|
+ log.error("读取文件失败", e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -143,7 +159,12 @@ public class LocalFileService extends AbstractFYunFileService {
|
|
|
|
|
|
@Override
|
|
|
public void downloadFile(String bucket, String remoteFilePath, String localPath) {
|
|
|
- FileUtil.copy(getOssPath(bucket, remoteFilePath), localPath, true);
|
|
|
+ try {
|
|
|
+ FileUtil.copy(getOssPath(bucket, remoteFilePath), localPath, true);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("下载文件失败,remoteFilePath:{},localPath:{}", remoteFilePath, localPath);
|
|
|
+ log.error("下载文件失败", e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|