use of com.upyun.UpException in project halo by ruibaby.
the class UpOssFileHandler method delete.
@Override
public void delete(String key) {
Assert.notNull(key, "File key must not be blank");
// Get config
String password = optionService.getByPropertyOfNonNull(UpOssProperties.OSS_PASSWORD).toString();
String bucket = optionService.getByPropertyOfNonNull(UpOssProperties.OSS_BUCKET).toString();
String operator = optionService.getByPropertyOfNonNull(UpOssProperties.OSS_OPERATOR).toString();
RestManager manager = new RestManager(bucket, operator, password);
manager.setTimeout(60 * 10);
manager.setApiDomain(RestManager.ED_AUTO);
try {
Response result = manager.deleteFile(key, null);
if (!result.isSuccessful()) {
log.warn("附件 " + key + " 从又拍云删除失败");
throw new FileOperationException("附件 " + key + " 从又拍云删除失败");
}
} catch (IOException | UpException e) {
e.printStackTrace();
throw new FileOperationException("附件 " + key + " 从又拍云删除失败", e);
}
}
use of com.upyun.UpException in project oss-spring-boot-starter by ArtIsLong.
the class UpOssClient method isExist.
@Override
public Boolean isExist(String targetName) {
String key = getKey(targetName, true);
try {
if (isFile(targetName)) {
Response response = restManager.getFileInfo(key);
String fileSize = response.header(RestManager.PARAMS.X_UPYUN_FILE_SIZE.getValue(), "0");
return Convert.toInt(fileSize) > 0;
} else {
DirectoryOssInfo ossInfo = getDirectoryOssInfo(key);
return Convert.toInt(ossInfo.getLength()) > 0;
}
} catch (IOException | UpException e) {
log.error("判断{}是否存在失败", targetName, e);
return false;
}
}
use of com.upyun.UpException in project oss-spring-boot-starter by ArtIsLong.
the class UpOssClient method move.
@Override
public void move(String sourceName, String targetName, Boolean isOverride) {
String newSourceName = getKey(sourceName, true);
String newTargetName = getKey(targetName, true);
try {
if (isFile(newSourceName)) {
restManager.moveFile(targetName, sourceName, null);
} else {
restManager.mkDir(newTargetName);
restManager.rmDir(newSourceName);
}
} catch (IOException | UpException e) {
log.error("{}移动到{}失败", sourceName, targetName, e);
throw new OssException(e);
}
}
Aggregations