Java Code Examples for com.aliyun.oss.OSSClient#deleteObject()

The following examples show how to use com.aliyun.oss.OSSClient#deleteObject() . 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: AliOssStorage.java    From springboot-learn with MIT License 6 votes vote down vote up
public void delete() {
    if (StringUtils.isAnyBlank(accessKeyId, accessKeySecret, endpoint, bucketName)) {
        throw new IllegalArgumentException("请先设置配置信息");
    }

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

    // 创建OSSClient实例。
    OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);

    // 删除文件。
    ossClient.deleteObject(bucketName, path);

    // 关闭OSSClient。
    ossClient.shutdown();
}
 
Example 2
Source File: AliFileManage.java    From sk-admin with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteFile(String key) {

    OssSetting os = getOssSetting();
    OSSClient ossClient = new OSSClient(os.getHttp() + os.getEndpoint(), new DefaultCredentialProvider(os.getAccessKey(), os.getSecretKey()), null);
    ossClient.deleteObject(os.getBucket(), key);
    ossClient.shutdown();
}
 
Example 3
Source File: ImgServiceImpl.java    From Tbed with GNU Affero General Public License v3.0 5 votes vote down vote up
public void delectOSS(Keys key, String fileName) {
    String endpoint = key.getEndpoint();
    String accessKeyId = key.getAccessKey();
    String accessKeySecret = key.getAccessSecret();
    String bucketName = key.getBucketname();
    String objectName = fileName;
    OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
    ossClient.deleteObject(bucketName, objectName);
    ossClient.shutdown();
}
 
Example 4
Source File: ApiBootOssService.java    From api-boot with Apache License 2.0 5 votes vote down vote up
@Override
public void delete(String objectName) throws ApiBootObjectStorageException {
    try {
        OSSClient ossClient = getOssClient();
        ossClient.deleteObject(bucketName, objectName);
        closeOssClient(ossClient);
    } catch (Exception e) {
        throw new ApiBootObjectStorageException(e.getMessage(), e);
    }
}
 
Example 5
Source File: AliyunOssUtils.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 删除一个OSS中的文件
 * @param objectName
 */
public static void delete(String objectName){
    boolean ossDelEnable = JPressOptions.getAsBool(KEY_OSS_DEL);
    if (ossDelEnable){
        OSSClient ossClient = createOSSClient();
        try {
            ossClient.deleteObject(JPressOptions.get(KEY_BUCKETNAME), objectName);
        }catch (Exception e){

        }finally {
            ossClient.shutdown();
        }
    }
}
 
Example 6
Source File: AliyunOSSClientUtil.java    From xmfcn-spring-cloud with Apache License 2.0 3 votes vote down vote up
/**
 * 根据key删除OSS服务器上的文件
 *
 * @param ossClient  oss连接
 * @param bucketName 存储空间
 * @param folder     模拟文件夹名 如"qj_nanjing/"
 * @param key        Bucket下的文件的路径名+文件名 如:"upload/cake.jpg"
 */
public static void deleteFile(OSSClient ossClient, String bucketName, String folder, String key) {
    String path=key;
    logger.info("删除" + bucketName + "下的文件"+path);
    ossClient.deleteObject(bucketName, path);
    logger.info("删除" + bucketName + "下的文件" + folder + key + "成功");
}