use of com.qiniu.storage.model.FileInfo in project eladmin by elunez.
the class QiNiuServiceImpl method synchronize.
@Override
@Transactional(rollbackFor = Exception.class)
public void synchronize(QiniuConfig config) {
if (config.getId() == null) {
throw new BadRequestException("请先添加相应配置,再操作");
}
// 构造一个带指定Zone对象的配置类
Configuration cfg = new Configuration(QiNiuUtil.getRegion(config.getZone()));
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 (qiniuContentRepository.findByKey(FileUtil.getFileNameNoEx(item.key)) == null) {
qiniuContent = new QiniuContent();
qiniuContent.setSize(FileUtil.getSize(Integer.parseInt(item.fsize + "")));
qiniuContent.setSuffix(FileUtil.getExtensionName(item.key));
qiniuContent.setKey(FileUtil.getFileNameNoEx(item.key));
qiniuContent.setType(config.getType());
qiniuContent.setBucket(config.getBucket());
qiniuContent.setUrl(config.getHost() + "/" + item.key);
qiniuContentRepository.save(qiniuContent);
}
}
}
}
use of com.qiniu.storage.model.FileInfo in project DimpleBlog by martin-chips.
the class QiNiuServiceImpl method synchronize.
@Override
@Transactional
public int synchronize() {
QiNiuConfig qiNiuConfig = getQiNiuConfig();
if (!qiNiuConfig.check()) {
throw new CustomException("七牛云配置信息不完整,请先填写七牛云配置信息");
}
// 构造一个带指定Zone对象的配置类
Configuration cfg = new Configuration(QiNiuUtils.getRegion(qiNiuConfig.getZone()));
Auth auth = Auth.create(qiNiuConfig.getAccessKey(), qiNiuConfig.getSecretKey());
BucketManager bucketManager = new BucketManager(auth, cfg);
// 文件名前缀
String prefix = "";
// 每次迭代的长度限制,最大1000,推荐值 1000
int limit = 1000;
// 指定目录分隔符,列出所有公共前缀(模拟列出目录效果)。缺省值为空字符串
String delimiter = "";
// 列举空间文件列表
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(qiNiuConfig.getBucket(), prefix, limit, delimiter);
int count = 0;
while (fileListIterator.hasNext()) {
// 处理获取的file list结果
QiNiuContent qiNiuContent;
// 删除所有数据
qiNiuContentMapper.clearContent();
FileInfo[] items = fileListIterator.next();
if (Objects.nonNull(items)) {
String username = SecurityUtils.getUsername();
for (FileInfo item : items) {
qiNiuContent = new QiNiuContent();
qiNiuContent.setSize(FileUtils.getSizeString(Integer.parseInt(item.fsize + "")));
qiNiuContent.setSuffix(FileUtils.getExtensionName(item.key));
qiNiuContent.setName(FileUtils.getFileNameNoExtension(item.key));
qiNiuContent.setType(qiNiuConfig.getType());
qiNiuContent.setBucket(qiNiuConfig.getBucket());
qiNiuContent.setUrl("http://" + qiNiuConfig.getHost() + "/" + item.key);
qiNiuContent.setCreateBy(username);
qiNiuContent.setCreateTime(convertUnixTime(item.putTime + ""));
count += qiNiuContentMapper.insertContent(qiNiuContent);
}
}
}
return count;
}
use of com.qiniu.storage.model.FileInfo in project accright-blog by Accright.
the class QiniuApi method getFileInfo.
public FileInfo getFileInfo(String fileName) {
BucketManager bucketManager = new BucketManager(this.auth);
FileInfo info = null;
try {
info = bucketManager.stat(config.getQiniuBucketName(), fileName);
log.info(info.hash);
log.info(info.key);
} catch (QiniuException e) {
Response r = e.response;
log.error(r.toString(), e);
}
return info;
}
use of com.qiniu.storage.model.FileInfo in project oss-spring-boot-starter by ArtIsLong.
the class QiNiuOssClient method getInfo.
@SneakyThrows
@Override
public OssInfo getInfo(String targetName, Boolean isRecursion) {
String key = getKey(targetName, false);
OssInfo ossInfo = getBaseInfo(targetName);
if (isRecursion && isDirectory(key)) {
FileListing listFiles = bucketManager.listFiles(getBucket(), key, "", 1000, "/");
System.out.println(listFiles);
List<OssInfo> fileOssInfos = new ArrayList<>();
List<OssInfo> directoryInfos = new ArrayList<>();
if (ObjectUtil.isNotEmpty(listFiles.items)) {
for (FileInfo fileInfo : listFiles.items) {
fileOssInfos.add(getInfo(OssPathUtil.replaceKey(fileInfo.key, getBasePath(), false), false));
}
}
if (ObjectUtil.isNotEmpty(listFiles.commonPrefixes)) {
for (String commonPrefix : listFiles.commonPrefixes) {
String target = OssPathUtil.replaceKey(commonPrefix, getBasePath(), true);
directoryInfos.add(getInfo(target, true));
}
}
if (ObjectUtil.isNotEmpty(fileOssInfos) && fileOssInfos.get(0) instanceof FileOssInfo) {
ReflectUtil.setFieldValue(ossInfo, "fileInfos", fileOssInfos);
}
if (ObjectUtil.isNotEmpty(directoryInfos) && directoryInfos.get(0) instanceof DirectoryOssInfo) {
ReflectUtil.setFieldValue(ossInfo, "directoryInfos", directoryInfos);
}
}
return ossInfo;
}
use of com.qiniu.storage.model.FileInfo in project Tbed by Hello-hao.
the class KODOImageupload method Initialize.
public static Integer Initialize(Keys k) {
int ret = -1;
if (k.getEndpoint() != null && k.getAccessSecret() != null && k.getEndpoint() != null && k.getBucketname() != null && k.getRequestAddress() != null) {
if (!k.getEndpoint().equals("") && !k.getAccessSecret().equals("") && !k.getEndpoint().equals("") && !k.getBucketname().equals("") && !k.getRequestAddress().equals("")) {
Configuration cfg;
if (k.getEndpoint().equals("1")) {
cfg = new Configuration(Zone.zone0());
} else if (k.getEndpoint().equals("2")) {
cfg = new Configuration(Zone.zone1());
} else if (k.getEndpoint().equals("3")) {
cfg = new Configuration(Zone.zone2());
} else if (k.getEndpoint().equals("4")) {
cfg = new Configuration(Zone.zoneNa0());
} else {
cfg = new Configuration(Zone.zoneAs0());
}
UploadManager uploadManager = new UploadManager(cfg);
Auth auth = Auth.create(k.getAccessKey(), k.getAccessSecret());
// auth.uploadToken(k.getBucketname());
String upToken = auth.uploadToken(k.getBucketname(), null, 7200, null);
BucketManager bmObj = new BucketManager(auth, cfg);
BucketManager.FileListIterator fileListIterator = null;
try {
fileListIterator = bmObj.createFileListIterator(k.getBucketname(), "", 1, "/");
FileInfo[] items = fileListIterator.next();
if (items != null) {
ret = 1;
bucketManager = bmObj;
key = k;
}
} catch (Exception e) {
System.out.println("KODO Object Is null");
ret = -1;
}
}
}
return ret;
}
Aggregations