Search in sources :

Example 6 with FileInfo

use of com.qiniu.storage.model.FileInfo in project blade-tool by chillzhuang.

the class QiniuTemplate method statFile.

@SneakyThrows
public OssFile statFile(String bucketName, String fileName) {
    FileInfo stat = bucketManager.stat(getBucketName(bucketName), fileName);
    OssFile ossFile = new OssFile();
    ossFile.setName(stat.key);
    ossFile.setName(Func.isEmpty(stat.key) ? fileName : stat.key);
    ossFile.setLink(fileLink(ossFile.getName()));
    ossFile.setHash(stat.hash);
    ossFile.setLength(stat.fsize);
    ossFile.setPutTime(new Date(stat.putTime / 10000));
    ossFile.setContentType(stat.mimeType);
    return ossFile;
}
Also used : FileInfo(com.qiniu.storage.model.FileInfo) OssFile(org.springblade.core.oss.model.OssFile) Date(java.util.Date) SneakyThrows(lombok.SneakyThrows)

Example 7 with FileInfo

use of com.qiniu.storage.model.FileInfo in project jeesuite-libs by vakinge.

the class QiniuProvider method getObjectMetadata.

@Override
public CObjectMetadata getObjectMetadata(String bucketName, String fileKey) {
    try {
        bucketName = buildBucketName(bucketName);
        FileInfo stat = bucketManager.stat(bucketName, fileKey);
        CObjectMetadata objectMetadata = new CObjectMetadata();
        objectMetadata.setCreateTime(new Date(stat.putTime));
        objectMetadata.setFilesize(stat.fsize);
        objectMetadata.setHash(stat.md5);
        objectMetadata.setMimeType(stat.mimeType);
        return objectMetadata;
    } catch (QiniuException e) {
        processQiniuException(bucketName, e);
        return null;
    }
}
Also used : CObjectMetadata(com.jeesuite.cos.CObjectMetadata) QiniuException(com.qiniu.common.QiniuException) FileInfo(com.qiniu.storage.model.FileInfo) Date(java.util.Date)

Example 8 with FileInfo

use of com.qiniu.storage.model.FileInfo in project jeesuite-libs by vakinge.

the class QiniuProvider method getObjectMetadata.

@Override
public CObjectMetadata getObjectMetadata(String bucketName, String fileKey) {
    try {
        bucketName = buildBucketName(bucketName);
        FileInfo stat = bucketManager.stat(bucketName, fileKey);
        CObjectMetadata objectMetadata = new CObjectMetadata();
        objectMetadata.setCreateTime(new Date(stat.putTime));
        objectMetadata.setFilesize(stat.fsize);
        objectMetadata.setHash(stat.md5);
        objectMetadata.setMimeType(stat.mimeType);
        return objectMetadata;
    } catch (QiniuException e) {
        processQiniuException(bucketName, e);
        return null;
    }
}
Also used : CObjectMetadata(com.mendmix.cos.CObjectMetadata) QiniuException(com.qiniu.common.QiniuException) FileInfo(com.qiniu.storage.model.FileInfo) Date(java.util.Date)

Example 9 with FileInfo

use of com.qiniu.storage.model.FileInfo in project waynboot-mall by wayn111.

the class QiniuContentServiceImpl method syncQiniu.

@Override
public boolean syncQiniu(QiniuConfig config) {
    // 构造一个带指定Zone对象的配置类
    Configuration cfg = new Configuration(QiniuUtil.getRegion(config.getRegion()));
    Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey());
    BucketManager bucketManager = new BucketManager(auth, cfg);
    // 文件名前缀
    String prefix = "";
    // 每次迭代的长度限制,最大1000,推荐值 1000
    int limit = 1000;
    // 指定目录分隔符,列出所有公共前缀(模拟列出目录效果)。缺省值为空字符串
    String delimiter = "";
    // 列举空间文件列表
    BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(config.getBucket(), prefix, limit, delimiter);
    while (fileListIterator.hasNext()) {
        // 处理获取的file list结果
        QiniuContent qiniuContent;
        FileInfo[] items = fileListIterator.next();
        for (FileInfo item : items) {
            if (getOne(new QueryWrapper<QiniuContent>().eq("name", FilenameUtils.getBaseName(item.key))) == null) {
                qiniuContent = new QiniuContent();
                qiniuContent.setSize(FileUtils.getSize(Integer.parseInt(item.fsize + "")));
                qiniuContent.setSuffix(FilenameUtils.getExtension(item.key));
                qiniuContent.setName(FilenameUtils.getBaseName(item.key));
                if (config.getType() == 0) {
                    qiniuContent.setType("公开");
                } else {
                    qiniuContent.setType("私有");
                }
                qiniuContent.setBucket(config.getBucket());
                qiniuContent.setUrl(config.getHost() + "/" + item.key);
                qiniuContent.setCreateTime(new Date());
                save(qiniuContent);
            }
        }
    }
    return true;
}
Also used : Configuration(com.qiniu.storage.Configuration) FileInfo(com.qiniu.storage.model.FileInfo) BucketManager(com.qiniu.storage.BucketManager) Auth(com.qiniu.util.Auth) QiniuContent(com.wayn.common.core.domain.tool.QiniuContent) Date(java.util.Date)

Example 10 with FileInfo

use of com.qiniu.storage.model.FileInfo in project oss-spring-boot-starter by ArtIsLong.

the class QiNiuOssClient method getBaseInfo.

private OssInfo getBaseInfo(String targetName) {
    String key = getKey(targetName, false);
    OssInfo ossInfo;
    if (isFile(targetName)) {
        ossInfo = new FileOssInfo();
        try {
            FileInfo fileInfo = bucketManager.stat(getBucket(), key);
            String putTime = DateUtil.date(fileInfo.putTime / 10000).toString(DatePattern.NORM_DATETIME_PATTERN);
            ossInfo.setLength(Convert.toStr(fileInfo.fsize));
            ossInfo.setCreateTime(putTime);
            ossInfo.setLastUpdateTime(putTime);
        } catch (QiniuException e) {
            String errorMsg = String.format("获取%s信息失败", targetName);
            log.error(errorMsg, e);
            throw new OssException(errorMsg, e);
        }
    } else {
        ossInfo = new DirectoryOssInfo();
    }
    ossInfo.setName(StrUtil.equals(targetName, StrUtil.SLASH) ? targetName : FileNameUtil.getName(targetName));
    ossInfo.setPath(OssPathUtil.replaceKey(targetName, ossInfo.getName(), true));
    return ossInfo;
}
Also used : QiniuException(com.qiniu.common.QiniuException) FileInfo(com.qiniu.storage.model.FileInfo) DirectoryOssInfo(io.github.artislong.model.DirectoryOssInfo) FileOssInfo(io.github.artislong.model.FileOssInfo) OssInfo(io.github.artislong.model.OssInfo) DirectoryOssInfo(io.github.artislong.model.DirectoryOssInfo) OssException(io.github.artislong.exception.OssException) FileOssInfo(io.github.artislong.model.FileOssInfo)

Aggregations

FileInfo (com.qiniu.storage.model.FileInfo)11 BucketManager (com.qiniu.storage.BucketManager)6 QiniuException (com.qiniu.common.QiniuException)5 Configuration (com.qiniu.storage.Configuration)5 Auth (com.qiniu.util.Auth)5 Date (java.util.Date)4 Transactional (org.springframework.transaction.annotation.Transactional)3 DirectoryOssInfo (io.github.artislong.model.DirectoryOssInfo)2 FileOssInfo (io.github.artislong.model.FileOssInfo)2 OssInfo (io.github.artislong.model.OssInfo)2 SneakyThrows (lombok.SneakyThrows)2 BadRequestException (co.yixiang.exception.BadRequestException)1 QiniuContent (co.yixiang.modules.tools.domain.QiniuContent)1 CustomException (com.dimple.common.exception.CustomException)1 QiNiuConfig (com.dimple.project.common.domain.QiNiuConfig)1 QiNiuContent (com.dimple.project.tool.domain.QiNiuContent)1 CObjectMetadata (com.jeesuite.cos.CObjectMetadata)1 CObjectMetadata (com.mendmix.cos.CObjectMetadata)1 Response (com.qiniu.http.Response)1 UploadManager (com.qiniu.storage.UploadManager)1