com.qiniu.storage.BucketManager Java Examples

The following examples show how to use com.qiniu.storage.BucketManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OptQiniuOssServiceImpl.java    From paascloud-master with Apache License 2.0 6 votes vote down vote up
@Override
public Set<String> batchDeleteFile(String[] fileNameList, String bucketName) throws QiniuException {
	log.info("batchDeleteFile - 删除OSS文件. fileNameList={}, bucketName={}", fileNameList, bucketName);
	BucketManager.BatchOperations batchOperations = new BucketManager.BatchOperations();
	batchOperations.addDeleteOp(bucketName, fileNameList);

	Response response = bucketManager.batch(batchOperations);
	BatchStatus[] batchStatusList = response.jsonToObject(BatchStatus[].class);

	Set<String> failSet = Sets.newHashSet();
	for (int i = 0; i < fileNameList.length; i++) {
		BatchStatus status = batchStatusList[i];
		String fileName = fileNameList[i];
		if (status.code != 200) {
			failSet.add(fileName);
			log.error("batchDeleteFile - 删除OSS文件. [FAIL] fileName={}, error={}", fileName, status.data.error);
		} else {
			log.info("batchDeleteFile - 删除OSS文件. [OK] fileName={}, bucketName={}", fileName, bucketName);
		}
	}
	return failSet;
}
 
Example #2
Source File: QiniuStorageImpl.java    From mblog with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void deleteFile(String storePath) {
    String accessKey = options.getValue(oss_key);
    String secretKey = options.getValue(oss_secret);
    String domain = options.getValue(oss_domain);
    String bucket = options.getValue(oss_bucket);

    if (StringUtils.isAnyBlank(accessKey, secretKey, domain, bucket)) {
        throw new MtonsException("请先在后台设置阿里云配置信息");
    }

    String path = StringUtils.remove(storePath, domain.trim());

    Zone z = Zone.autoZone();
    Configuration configuration = new Configuration(z);
    Auth auth = Auth.create(accessKey, secretKey);

    BucketManager bucketManager = new BucketManager(auth, configuration);
    try {
        bucketManager.delete(bucket, path);
    } catch (QiniuException e) {
        Response r = e.response;
        log.error(e.getMessage(), r.toString());
    }
}
 
Example #3
Source File: QiniuServiceImpl.java    From jframe with Apache License 2.0 6 votes vote down vote up
@Start
void start() {
    try {
        CONFIG.init(PLUGIN.getConfig(FILE_CONF));
        if ("".equals(CONFIG.getConf(null,
                QiniuConfig.AK))) { throw new ServiceException("Error in configuration , lost parameter -> " + QiniuConfig.AK); }
        if ("".equals(CONFIG.getConf(null,
                QiniuConfig.SK))) { throw new ServiceException("Error in configuration , lost parameter -> " + QiniuConfig.SK); }

        LOG.info("QiniuService {}", CONFIG);
        AUTH = Auth.create(CONFIG.getConf(null, QiniuConfig.AK), CONFIG.getConf(null, QiniuConfig.SK));
        BUCKET = new BucketManager(AUTH, new Configuration());

        LOG.info("QiniuService start successfully!");
    } catch (Exception e) {
        LOG.error("QiniuService start error -> {}", e.getMessage());
    }
}
 
Example #4
Source File: QiniuProvider.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
public QiniuProvider(String urlprefix, String bucketName, String accessKey, String secretKey,boolean isPrivate) {
	
	Validate.notBlank(bucketName, "[bucketName] not defined");
	Validate.notBlank(accessKey, "[accessKey] not defined");
	Validate.notBlank(secretKey, "[secretKey] not defined");
	Validate.notBlank(urlprefix, "[urlprefix] not defined");
	
	this.urlprefix = urlprefix.endsWith(DIR_SPLITER) ? urlprefix : urlprefix + DIR_SPLITER;
	this.bucketName = bucketName;
	auth = Auth.create(accessKey, secretKey);

	Zone region = Zone.autoZone();
	Configuration c = new Configuration(region);
	uploadManager = new UploadManager(c);
	bucketManager = new BucketManager(auth,c);
	
	this.isPrivate = isPrivate;
	this.host = StringUtils.remove(urlprefix,"/").split(":")[1];
}
 
Example #5
Source File: QiNiuUtil.java    From javabase with Apache License 2.0 6 votes vote down vote up
/**
 * 列举指定前缀的文件
 *
 * @param prefix
 */
public void fileList(String prefix) {
    //每次迭代的长度限制,最大1000,推荐值 1000
    int limit = 1000;
    //指定目录分隔符,列出所有公共前缀(模拟列出目录效果)。缺省值为空字符串
    String delimiter = "";
    //列举空间文件列表
    BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(bucketName, prefix, limit, delimiter);
    while (fileListIterator.hasNext()) {
        //处理获取的file list结果
        FileInfo[] items = fileListIterator.next();
        for (FileInfo item : items) {
            log.info(item.key);
        }
    }
}
 
Example #6
Source File: QiNiuUtil.java    From javabase with Apache License 2.0 6 votes vote down vote up
/**
 * 删除图片
 * https://developer.qiniu.com/kodo/sdk/java#rs-batch-delete
 * 每次只能删除小于1000条数据
 *
 * @param list
 */
public void deleteByList(List<String> list) {
    try {
        if (list == null) return;
        log.info("待删除图片大小:{}", list.size());
        String[] keyList = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            keyList[i] = list.get(i).replace(domain, "");
        }
        BucketManager.BatchOperations batchOperations = new BucketManager.BatchOperations();
        batchOperations.addDeleteOp(bucketName, keyList);
        Response response = bucketManager.batch(batchOperations);
        BatchStatus[] batchStatusList = response.jsonToObject(BatchStatus[].class);
        /*for (int k = 0; k < keyList.length; k++) {
            BatchStatus status = batchStatusList[k];
            if (status.code == 200) {
               // log.info("delete success");
            } else {
                log.error("删除失败", status.toString());
            }
        }*/
    } catch (QiniuException e) {
        log.error("七牛上传 response:" + e.getLocalizedMessage());
    }
}
 
Example #7
Source File: QiNiuUtil.java    From javabase with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
    Configuration cfg = new Configuration(Zone.zone0());
    cfg.connectTimeout=5000;
    cfg.readTimeout=5000;
    cfg.writeTimeout=2000;
    auth = Auth.create(accessKey, secretKey);
    uploadManager = new UploadManager(cfg);
    // 实例化一个BucketManager对象
    bucketManager = new BucketManager(auth, cfg);

    new Thread() {
        public void run() {
            deleteBlockingDequeImage();
        }
    }.start();
}
 
Example #8
Source File: QiniuService.java    From qiniu with MIT License 6 votes vote down vote up
/**
 * 获取空间文件列表
 */
public void listFile() {
    MainController main = MainController.getInstance();
    // 列举空间文件列表
    BucketManager.FileListIterator iterator = sdkManager.getFileListIterator(main.bucketCB.getValue());
    ArrayList<FileBean> files = new ArrayList<>();
    main.setDataLength(0);
    main.setDataSize(0);
    // 处理结果
    while (iterator.hasNext()) {
        FileInfo[] items = iterator.next();
        for (FileInfo item : items) {
            main.setDataLength(main.getDataLength() + 1);
            main.setDataSize(main.getDataSize() + item.fsize);
            // 将七牛的时间单位(100纳秒)转换成毫秒,然后转换成时间
            String time = Formatter.timeStampToString(item.putTime / 10000);
            String size = Formatter.formatSize(item.fsize);
            FileBean file = new FileBean(item.key, item.mimeType, size, time);
            files.add(file);
        }
    }
    main.setResData(FXCollections.observableArrayList(files));
}
 
Example #9
Source File: QiniuApiClient.java    From OneBlog with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 删除七牛空间图片方法
 *
 * @param key 七牛空间中文件名称
 */
@Override
public boolean removeFile(String key) {
    this.check();

    if (StringUtils.isNullOrEmpty(key)) {
        throw new QiniuApiException("[" + this.storageType + "]删除文件失败:文件key为空");
    }
    Auth auth = Auth.create(this.accessKey, this.secretKey);
    Configuration config = new Configuration(Region.autoRegion());
    BucketManager bucketManager = new BucketManager(auth, config);
    try {
        Response re = bucketManager.delete(this.bucket, key);
        return re.isOK();
    } catch (QiniuException e) {
        Response r = e.response;
        throw new QiniuApiException("[" + this.storageType + "]删除文件发生异常:" + r.toString());
    }
}
 
Example #10
Source File: QiniuFileUtil.java    From mysiteforme with Apache License 2.0 6 votes vote down vote up
/***
 * 上传网络图片
 * @param src
 * @return
 */
public static String uploadImageSrc(String src){
	Zone z = Zone.zone0();
	Configuration config = new Configuration(z);
	Auth auth = Auth.create(qiniuAccess, qiniuKey);
	BucketManager bucketManager = new BucketManager(auth, config);
	String fileName = UUID.randomUUID().toString(),filePath="";
	try {
		FetchRet fetchRet = bucketManager.fetch(src, bucketName);
		filePath = path + fetchRet.key;
		Rescource rescource = new Rescource();
		rescource.setFileName(fetchRet.key);
		rescource.setFileSize(new java.text.DecimalFormat("#.##").format(fetchRet.fsize/1024)+"kb");
		rescource.setHash(fetchRet.hash);
		rescource.setFileType(fetchRet.mimeType);
		rescource.setWebUrl(filePath);
		rescource.setSource("qiniu");
		rescource.insert();
	} catch (QiniuException e) {
		filePath = src;
		e.printStackTrace();
	}
	return filePath;
}
 
Example #11
Source File: QiniuCloud.java    From rebuild with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 删除文件
 * 
 * @param key
 * @return
 */
protected boolean delete(String key) {
	Assert.notNull(auth, "云存储账户未配置");
	BucketManager bucketManager = new BucketManager(auth, CONFIGURATION);
	Response resp;
	try {
		resp = bucketManager.delete(this.bucketName, key);
		if (resp.isOK()) {
			return true;
		} else {
			throw new RebuildException("删除文件失败 : " + this.bucketName + " < " + key + " : " + resp.bodyString());
		}
	} catch (QiniuException e) {
		throw new RebuildException("删除文件失败 : " + this.bucketName + " < " + key, e);
	}
}
 
Example #12
Source File: FileService.java    From ml-blog with MIT License 6 votes vote down vote up
/**
 * 文件删除
 * @param key
 * @return
 */
public Response delete(String key) throws GlobalException{

    // 有配置数据,但上传凭证为空
    if (!commonMap.containsKey("upToken")) {
        // 创建七牛云组件
        createQiniuComponent();
    }

    try {
        BucketManager bucketManager = (BucketManager) commonMap.get("bucketManager");
        String bucket = commonMap.get("qn_bucket").toString();
        Response response = bucketManager.delete(bucket, key);
        int retry = 0;
        while(response.needRetry() && retry < 3) {
            response = bucketManager.delete(bucket, key);
            retry++;
        }
        return response;
    } catch (QiniuException ex) {
        log.error("文件删除异常:",ex.toString());
        throw new GlobalException(500, ex.toString());
    }
}
 
Example #13
Source File: AttachmentServiceImpl.java    From blog-sharon with Apache License 2.0 6 votes vote down vote up
/**
 * 七牛云删除附件
 *
 * @param key key
 * @return boolean
 */
@Override
public boolean deleteQiNiuAttachment(String key) {
    boolean flag = true;
    Configuration cfg = new Configuration(Zone.zone0());
    String accessKey = HaloConst.OPTIONS.get("qiniu_access_key");
    String secretKey = HaloConst.OPTIONS.get("qiniu_secret_key");
    String bucket = HaloConst.OPTIONS.get("qiniu_bucket");
    if (StrUtil.isEmpty(accessKey) || StrUtil.isEmpty(secretKey) || StrUtil.isEmpty(bucket)) {
        return false;
    }
    Auth auth = Auth.create(accessKey, secretKey);
    BucketManager bucketManager = new BucketManager(auth, cfg);
    try {
        bucketManager.delete(bucket, key);
    } catch (QiniuException ex) {
        System.err.println(ex.code());
        System.err.println(ex.response.toString());
        flag = false;
    }
    return flag;
}
 
Example #14
Source File: QiNiuStorage.java    From springboot-learn with MIT License 6 votes vote down vote up
public void deleteFile() {
    if (StringUtils.isAnyBlank(accessKey, secretKey, domain, bucket)) {
        throw new IllegalArgumentException("请先设置配置信息");
    }

    //文件所在的目录名
    String fileDir = "image/jpg/";
    //文件名
    String key = "user.png";

    String path = StringUtils.remove(fileDir + key, domain.trim());

    Zone z = Zone.autoZone();
    Configuration configuration = new Configuration(z);
    Auth auth = Auth.create(accessKey, secretKey);

    BucketManager bucketManager = new BucketManager(auth, configuration);
    try {
        bucketManager.delete(bucket, path);
    } catch (QiniuException e) {
        Response r = e.response;
        System.out.println(e.response.getInfo());
    }
}
 
Example #15
Source File: AttachmentServiceImpl.java    From SENS with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 七牛云删除附件
 *
 * @param key key
 * @return boolean
 */
@Override
public boolean deleteQiNiuAttachment(String key) {
    boolean flag = true;
    final Configuration cfg = new Configuration(Zone.zone0());
    final String accessKey = SensConst.OPTIONS.get("qiniu_access_key");
    final String secretKey = SensConst.OPTIONS.get("qiniu_secret_key");
    final String bucket = SensConst.OPTIONS.get("qiniu_bucket");
    if (StrUtil.isEmpty(accessKey) || StrUtil.isEmpty(secretKey) || StrUtil.isEmpty(bucket)) {
        return false;
    }
    final Auth auth = Auth.create(accessKey, secretKey);
    final BucketManager bucketManager = new BucketManager(auth, cfg);
    try {
        bucketManager.delete(bucket, key);
    } catch (QiniuException ex) {
        System.err.println(ex.code());
        System.err.println(ex.response.toString());
        flag = false;
    }
    return flag;
}
 
Example #16
Source File: AttachmentServiceImpl.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 七牛云删除附件
 *
 * @param key key
 * @return boolean
 */
@Override
public boolean deleteQiNiuAttachment(String key) {
    boolean flag = true;
    final Configuration cfg = new Configuration(Zone.zone0());
    final String accessKey = HaloConst.OPTIONS.get("qiniu_access_key");
    final String secretKey = HaloConst.OPTIONS.get("qiniu_secret_key");
    final String bucket = HaloConst.OPTIONS.get("qiniu_bucket");
    if (StrUtil.isEmpty(accessKey) || StrUtil.isEmpty(secretKey) || StrUtil.isEmpty(bucket)) {
        return false;
    }
    final Auth auth = Auth.create(accessKey, secretKey);
    final BucketManager bucketManager = new BucketManager(auth, cfg);
    try {
        bucketManager.delete(bucket, key);
    } catch (QiniuException ex) {
        System.err.println(ex.code());
        System.err.println(ex.response.toString());
        flag = false;
    }
    return flag;
}
 
Example #17
Source File: QiniuFileUtil.java    From mysiteforme with Apache License 2.0 5 votes vote down vote up
/***
 * 删除已经上传的图片
 * @param imgPath
 */
public static void deleteQiniuP(String imgPath) {
	Zone z = Zone.zone0();
	Configuration config = new Configuration(z);
	Auth auth = Auth.create(qiniuAccess, qiniuKey);
	BucketManager bucketManager = new BucketManager(auth,config);
	imgPath = imgPath.replace(path, "");
	try {
		bucketManager.delete(bucketName, imgPath);
	} catch (QiniuException e) {
		e.printStackTrace();
	}
}
 
Example #18
Source File: QiNiuServiceImpl.java    From sk-admin with Apache License 2.0 5 votes vote down vote up
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void synchronize(QiniuConfig config) {
    if (config.getId() == null) {
        throw new SkException("请先添加相应配置,再操作");
    }
    //构造一个带指定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 (qiniuContentDao.findByKey(FileUtils.getFileNameNoEx(item.key)) == null) {
                qiniuContent = new QiniuContent();
                qiniuContent.setSize(FileUtils.getSize(Integer.parseInt(item.fsize + "")));
                qiniuContent.setSuffix(FileUtils.getExtensionName(item.key));
                qiniuContent.setKey(FileUtils.getFileNameNoEx(item.key));
                qiniuContent.setType(config.getType());
                qiniuContent.setBucket(config.getBucket());
                qiniuContent.setUrl(config.getHost() + "/" + item.key);
                qiniuContentDao.save(qiniuContent);
            }
        }
    }
}
 
Example #19
Source File: QiNiuFileManage.java    From sk-admin with Apache License 2.0 5 votes vote down vote up
@Override
public String renameFile(String fromKey, String toKey) {

    OssSetting os = getOssSetting();
    Auth auth = Auth.create(os.getAccessKey(), os.getSecretKey());
    BucketManager bucketManager = new BucketManager(auth, getConfiguration(os.getZone()));
    try {
        bucketManager.move(os.getBucket(), fromKey, os.getBucket(), toKey);
        return os.getHttp() + os.getEndpoint() + "/" + toKey;
    } catch (QiniuException ex) {
        throw new SkException("重命名文件失败," + ex.response.toString());
    }
}
 
Example #20
Source File: QiNiuFileManage.java    From sk-admin with Apache License 2.0 5 votes vote down vote up
@Override
public String copyFile(String fromKey, String toKey) {

    OssSetting os = getOssSetting();
    Auth auth = Auth.create(os.getAccessKey(), os.getSecretKey());
    BucketManager bucketManager = new BucketManager(auth, getConfiguration(os.getZone()));
    try {
        bucketManager.copy(os.getBucket(), fromKey, os.getBucket(), toKey);
        return os.getHttp() + os.getEndpoint() + "/" + toKey;
    } catch (QiniuException ex) {
        throw new SkException("复制文件失败," + ex.response.toString());
    }
}
 
Example #21
Source File: QiNiuUtil.java    From javabase with Apache License 2.0 5 votes vote down vote up
public void deleteFileList(String prefix) throws Exception {
    BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(bucketName, prefix, 1000, "");
    while (fileListIterator.hasNext()) {
        //处理获取的file list结果
        FileInfo[] items = fileListIterator.next();
        List<String> list = new ArrayList<>(items.length);
        for (FileInfo item : items) {
            list.add(item.key);
        }
       getDeleteBlockingDeque().put(list);
    }
}
 
Example #22
Source File: QiNiuFileManage.java    From sk-admin with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteFile(String key) {

    OssSetting os = getOssSetting();
    Auth auth = Auth.create(os.getAccessKey(), os.getSecretKey());
    BucketManager bucketManager = new BucketManager(auth, getConfiguration(os.getZone()));
    try {
        bucketManager.delete(os.getBucket(), key);
    } catch (QiniuException ex) {
        throw new SkException("删除文件失败," + ex.response.toString());
    }
}
 
Example #23
Source File: QiniuFileProvider.java    From xiaoyaoji with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 删除文件
 *
 * @param path 文件路径
 */
@Override
public boolean delete(String path) throws IOException {
    Auth auth = Auth.create(ConfigUtils.getQiniuAccessKey(), ConfigUtils.getQiniuSecretKey());
    BucketManager bucketManager = new BucketManager(auth);
    try {
        bucketManager.delete(ConfigUtils.getBucketURL(), path);
        return true;
    } catch (QiniuException e) {
        Response r = e.response;
        throw new IOException(r.bodyString());
    }
}
 
Example #24
Source File: SdkManager.java    From qiniu with MIT License 5 votes vote down vote up
/**
 * 批量删除文件,单次批量请求的文件数量不得超过1000
 */
public BatchStatus[] batchDelete(String bucket, String[] keys) throws QiniuException {
    BucketManager.BatchOperations batchOperations = new BucketManager.BatchOperations();
    batchOperations.addDeleteOp(bucket, keys);
    Response response = SdkConfigurer.getBucketManager().batch(batchOperations);
    return response.jsonToObject(BatchStatus[].class);
}
 
Example #25
Source File: QiniuProvider.java    From azeroth with Apache License 2.0 5 votes vote down vote up
public QiniuProvider(String urlprefix, String bucketName, String accessKey, String secretKey) {
    this.urlprefix = urlprefix.endsWith(DIR_SPLITER) ? urlprefix : urlprefix + DIR_SPLITER;
    this.bucketName = bucketName;
    auth = Auth.create(accessKey, secretKey);

    Zone z = Zone.autoZone();
    Configuration c = new Configuration(z);
    uploadManager = new UploadManager(c);
    bucketManager = new BucketManager(auth, c);
}
 
Example #26
Source File: QiniuStorageManager.java    From sanshanblog with Apache License 2.0 5 votes vote down vote up
/**
 *
 根据名字删除文件
 */
public void ueditorDeleteFile(String filename) {
    Auth auth = Auth.create(accessKey, secretKey);
    BucketManager bucketManager = new BucketManager(auth, cfg);
    try {
        bucketManager.delete(ueditor_bucket,filename);
    } catch (QiniuException e) {
        //删除失败
        log.error(e.getMessage());
        e.printStackTrace();
    }
}
 
Example #27
Source File: QiNiuUtil.java    From spring-microservice-exam with MIT License 5 votes vote down vote up
public QiNiuUtil() {
	qiNiuConfig = SpringContextHolder.getApplicationContext().getBean(QiNiuConfig.class);
	if (StringUtils.isNotBlank(qiNiuConfig.getAccessKey()) && StringUtils.isNotBlank(qiNiuConfig.getSecretKey())) {
		instance = new QiNiuUtil();
		instance.auth = Auth.create(qiNiuConfig.getAccessKey(), qiNiuConfig.getSecretKey());
		Configuration config = new Configuration(Region.region2());
		instance.uploadManager = new UploadManager(config);
		instance.bucketManager = new BucketManager(instance.auth, config);
	}
}
 
Example #28
Source File: QiNiuCloudTemplate.java    From magic-starter with GNU Lesser General Public License v3.0 5 votes vote down vote up
public QiNiuCloudTemplate(Auth auth, UploadManager uploadManager, BucketManager bucketManager, OssProperties ossProperties, OssRule ossRule) {
	super(ossProperties, ossRule, OssType.QINIU_CLOUD);
	this.auth = auth;
	this.uploadManager = uploadManager;
	this.bucketManager = bucketManager;
	this.ossProperties = ossProperties;
}
 
Example #29
Source File: QiniuOssFileHandler.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void delete(String key) {
    Assert.notNull(key, "File key must not be blank");

    Region region = optionService.getQiniuRegion();

    String accessKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_ACCESS_KEY).toString();
    String secretKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_SECRET_KEY).toString();
    String bucket = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_BUCKET).toString();

    // Create configuration
    Configuration configuration = new Configuration(region);

    // Create auth
    Auth auth = Auth.create(accessKey, secretKey);

    BucketManager bucketManager = new BucketManager(auth, configuration);

    try {
        Response response = bucketManager.delete(bucket, key);
        if (!response.isOK()) {
            log.warn("附件 " + key + " 从七牛云删除失败");
        }
    } catch (QiniuException e) {
        log.error("Qiniu oss error response: [{}]", e.response);
        throw new FileOperationException("附件 " + key + " 从七牛云删除失败", e);
    }
}
 
Example #30
Source File: QiNiuServiceImpl.java    From sk-admin with Apache License 2.0 5 votes vote down vote up
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void delete(QiniuContent content, QiniuConfig config) {
    //构造一个带指定Zone对象的配置类
    Configuration cfg = new Configuration(QiNiuUtil.getRegion(config.getZone()));
    Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey());
    BucketManager bucketManager = new BucketManager(auth, cfg);
    try {
        bucketManager.delete(content.getBucket(), content.getKey() + "." + content.getSuffix());
        qiniuContentDao.delete(content);
    } catch (QiniuException ex) {
        qiniuContentDao.delete(content);
    }
}