Java Code Examples for com.qiniu.util.Auth#privateDownloadUrl()

The following examples show how to use com.qiniu.util.Auth#privateDownloadUrl() . 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: FileServiceQiNiuYun.java    From smart-admin with MIT License 6 votes vote down vote up
@Override
public ResponseDTO<String> getFileUrl(String path) {
    OSSConfig ossConfig = systemConfigService.selectByKey2Obj(SystemConfigEnum.Key.QI_NIU_OSS.name(), OSSConfig.class);
    try {
        if (! ossConfig.toString().equals(accessConfig)) {
            //accessKeyId 发生变动自动重新创建新的UploadManager
            ossClient = new UploadManager(new Configuration());
            token = Auth.create(ossConfig.getAccessKeyId(), ossConfig.getAccessKeySecret()).
                uploadToken(ossConfig.getBucketName());
            accessConfig = ossConfig.toString();
        }
        String encodedFileName = URLEncoder.encode(path, "utf-8");
        String domainOfBucket = ossConfig.getEndpoint();
        String publicUrl = String.format("%s/%s", domainOfBucket, encodedFileName);
        String accessKey = ossConfig.getAccessKeyId();
        String secretKey = ossConfig.getAccessKeySecret();
        Auth auth = Auth.create(accessKey, secretKey);
        //1小时,可以自定义链接过期时间
        long expireInSeconds = 3600;
        String finalUrl = auth.privateDownloadUrl(publicUrl, expireInSeconds);
        return ResponseDTO.succData(finalUrl);
    } catch (Exception e) {
        log.error("QINIU getFileUrl ERROR : {}", e);
    }
    return ResponseDTO.wrap(FileResponseCodeConst.URL_ERROR);
}
 
Example 2
Source File: QiNiuServiceImpl.java    From DimpleBlog with Apache License 2.0 6 votes vote down vote up
@Override
public String getDownloadUrl(Long id) {
    QiNiuConfig qiNiuConfig = getQiNiuConfig();
    if (!qiNiuConfig.check()) {
        throw new CustomException("七牛云配置信息不完整,请先填写七牛云配置信息");
    }
    QiNiuContent qiNiuContent = qiNiuContentMapper.selectContentById(id);
    if (Objects.isNull(qiNiuConfig)) {
        throw new CustomException("对应文件不存在,建议同步数据后再试");
    }
    if ("公开".equals(qiNiuConfig.getType())) {
        return qiNiuContent.getUrl();
    } else {
        Auth auth = Auth.create(qiNiuConfig.getAccessKey(), qiNiuConfig.getSecretKey());
        // 1小时,可以自定义链接过期时间
        long expireInSeconds = 3600;
        return auth.privateDownloadUrl(qiNiuContent.getUrl(), expireInSeconds);
    }
}
 
Example 3
Source File: QiNiuServiceImpl.java    From sk-admin with Apache License 2.0 5 votes vote down vote up
@Override
@Cacheable
public String download(QiniuContent content, QiniuConfig config) {
    String finalUrl;
    String type = "公开";
    if (type.equals(content.getType())) {
        finalUrl = content.getUrl();
    } else {
        Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey());
        // 1小时,可以自定义链接过期时间
        long expireInSeconds = 3600;
        finalUrl = auth.privateDownloadUrl(content.getUrl(), expireInSeconds);
    }
    return finalUrl;
}
 
Example 4
Source File: FileServiceQiNiuYun.java    From smart-admin with MIT License 5 votes vote down vote up
/**
 * 获取下载路径
 */
public String getDownloadUrl(String key) {
    OSSConfig ossConfig = systemConfigService.selectByKey2Obj(SystemConfigEnum.Key.QI_NIU_OSS.name(), OSSConfig.class);
    String domainOfBucket = ossConfig.getEndpoint();
    String finalUrl = "";
    try {
        String encodedFileName = URLEncoder.encode(key, "utf-8").replace("+", "%20");
        String publicUrl = String.format("%s/%s", domainOfBucket, encodedFileName);
        Auth auth = Auth.create(ossConfig.getAccessKeyId(), ossConfig.getAccessKeySecret());
        finalUrl = auth.privateDownloadUrl(publicUrl, expireInSeconds);
    } catch (Exception e) {
        log.error("QINIU download ERROR : {}", e);
    }
    return finalUrl;
}
 
Example 5
Source File: QiNiuServiceImpl.java    From yshopmall with Apache License 2.0 5 votes vote down vote up
@Override
//    @Cacheable
    public String download(QiniuContent content,QiniuConfig config){
        String finalUrl;
        String type = "公开";
        if(type.equals(content.getType())){
            finalUrl  = content.getUrl();
        } else {
            Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey());
            // 1小时,可以自定义链接过期时间
            long expireInSeconds = 3600;
            finalUrl = auth.privateDownloadUrl(content.getUrl(), expireInSeconds);
        }
        return finalUrl;
    }
 
Example 6
Source File: QiniuUtils.java    From spring-admin-vue with Apache License 2.0 5 votes vote down vote up
/**
 * 获取私有空间文件
 *
 * @param fileKey
 * @return String
 * @throws Exception
 */
public String getPrivateFile(String fileKey) throws Exception {
    String encodedFileName = URLEncoder.encode(fileKey, "utf-8").replace("+", "%20");
    String url = String.format("%s/%s", fileDomain, encodedFileName);
    Auth auth = Auth.create(accessKey, secretKey);
    long expireInSeconds = 3600;
    //1小时,可以自定义链接过期时间
    return auth.privateDownloadUrl(url, expireInSeconds);
}
 
Example 7
Source File: QiNiuServiceImpl.java    From eladmin with Apache License 2.0 5 votes vote down vote up
@Override
public String download(QiniuContent content,QiniuConfig config){
    String finalUrl;
    String type = "公开";
    if(type.equals(content.getType())){
        finalUrl  = content.getUrl();
    } else {
        Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey());
        // 1小时,可以自定义链接过期时间
        long expireInSeconds = 3600;
        finalUrl = auth.privateDownloadUrl(content.getUrl(), expireInSeconds);
    }
    return finalUrl;
}