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;
}
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;
}
}
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;
}
}
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;
}
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;
}
Aggregations