Search in sources :

Example 6 with UpException

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);
    }
}
Also used : Response(okhttp3.Response) UpException(com.upyun.UpException) FileOperationException(run.halo.app.exception.FileOperationException) RestManager(com.upyun.RestManager) IOException(java.io.IOException)

Example 7 with UpException

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;
    }
}
Also used : Response(okhttp3.Response) UpException(com.upyun.UpException) DirectoryOssInfo(io.github.artislong.model.DirectoryOssInfo)

Example 8 with UpException

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);
    }
}
Also used : UpException(com.upyun.UpException) OssException(io.github.artislong.exception.OssException)

Aggregations

UpException (com.upyun.UpException)8 Response (okhttp3.Response)7 RestManager (com.upyun.RestManager)5 OssException (io.github.artislong.exception.OssException)4 DirectoryOssInfo (io.github.artislong.model.DirectoryOssInfo)3 IOException (java.io.IOException)3 FileOperationException (run.halo.app.exception.FileOperationException)3 Convert (cn.hutool.core.convert.Convert)2 DatePattern (cn.hutool.core.date.DatePattern)2 DateUtil (cn.hutool.core.date.DateUtil)2 IoUtil (cn.hutool.core.io.IoUtil)2 LineHandler (cn.hutool.core.io.LineHandler)2 FileNameUtil (cn.hutool.core.io.file.FileNameUtil)2 ObjectUtil (cn.hutool.core.util.ObjectUtil)2 ReflectUtil (cn.hutool.core.util.ReflectUtil)2 StrUtil (cn.hutool.core.util.StrUtil)2 ParallelUploader (com.upyun.ParallelUploader)2 StandardOssClient (io.github.artislong.core.StandardOssClient)2 UpConstant (io.github.artislong.core.up.constant.UpConstant)2 UpOssConfig (io.github.artislong.core.up.model.UpOssConfig)2