Java Code Examples for com.qiniu.common.Zone#autoZone()
The following examples show how to use
com.qiniu.common.Zone#autoZone() .
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: QiniuStorageImpl.java From mblog with GNU General Public License v3.0 | 6 votes |
@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 2
Source File: QiniuProvider.java From jeesuite-libs with Apache License 2.0 | 6 votes |
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 3
Source File: QiNiuStorage.java From springboot-learn with MIT License | 6 votes |
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 4
Source File: QiniuOssConfiguration.java From paascloud-master with Apache License 2.0 | 5 votes |
/** * Bucket manager bucket manager. * * @return the bucket manager */ @Bean public BucketManager bucketManager() { Zone zone = Zone.autoZone(); //创建上传对象 BucketManager uploadManager = new BucketManager(auth(), new com.qiniu.storage.Configuration(zone)); log.info("Create BucketManager OK."); return uploadManager; }
Example 5
Source File: QiniuOSSTest.java From mblog with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws IOException, InterruptedException { File file = new File("F:/data/a_2.jpg"); byte[] bytes = ImageUtils.screenshot(file, 360, 200); final String key = "/static" + UpYunUtils.md5(bytes) + ".jpg"; Zone z = Zone.autoZone(); Configuration configuration = new Configuration(z); final Auth auth = Auth.create(accessKey, secretKey); final String upToken = auth.uploadToken(bucket, key); try { final UploadManager uploadManager = new UploadManager(configuration); final Response response = uploadManager.put(bytes, key, upToken); System.out.println(response.bodyString()); System.out.println(response.isOK()); } catch (QiniuException e) { final Response r = e.response; System.err.println(r.toString()); try { System.err.println(r.bodyString()); } catch (QiniuException ex2) { //ignore } } String filePath = domain.trim()+ key + ".jpg"; System.out.println(filePath); }
Example 6
Source File: QiniuStorageImpl.java From mblog with GNU General Public License v3.0 | 5 votes |
@Override public String writeToStore(byte[] bytes, String pathAndFileName) throws Exception { String accessKey = options.getValue(oss_key); String secretKey = options.getValue(oss_secret); String domain = options.getValue(oss_domain); String bucket = options.getValue(oss_bucket); String src = options.getValue(oss_src); if (StringUtils.isAnyBlank(accessKey, secretKey, domain, bucket)) { throw new MtonsException("请先在后台设置阿里云配置信息"); } if (StringUtils.isNotBlank(src)) { if (src.startsWith("/")) { src = src.substring(1); } if (!src.endsWith("/")) { src = src + "/"; } } else { src = ""; } String key = UpYunUtils.md5(bytes); String path = src + key + FileKit.getSuffix(pathAndFileName); Zone z = Zone.autoZone(); Configuration configuration = new Configuration(z); Auth auth = Auth.create(accessKey, secretKey); String upToken = auth.uploadToken(bucket, path); UploadManager uploadManager = new UploadManager(configuration); Response response = uploadManager.put(bytes, path, upToken); if (!response.isOK()) { throw new MtonsException(response.bodyString()); } return domain.trim() + "/" + path; }
Example 7
Source File: QiniuProvider.java From azeroth with Apache License 2.0 | 5 votes |
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 8
Source File: QNUploader.java From SmartIM with Apache License 2.0 | 5 votes |
public UploadInfo upload(String qq, File file, String ak, String sk, String bucket, Zone zone) throws Exception { // 默认不指定key的情况下,以文件内容的hash值作为文件名 String key = String.format("%s/%s", qq, file.getName()); AuthInfo authInfo = getToken(qq, ak, sk, bucket, key); System.out.println(authInfo); if (authInfo.limit > 0 && file.length() > authInfo.limit) { throw new RuntimeException("今日上传流量不足,剩余流量:" + authInfo.limit); } // 构造一个带指定Zone对象的配置类 Configuration cfg = new Configuration( zone == null ? Zone.autoZone() : zone); // ...其他参数参考类注释 UploadManager uploadManager = new UploadManager(cfg); com.qiniu.http.Response response = uploadManager .put(file.getAbsolutePath(), key, authInfo.token); if (!response.isOK()) { throw new RuntimeException( response.error + "(code=" + response.statusCode + ")"); } // 解析上传成功的结果 UploadInfo putRet = new Gson().fromJson(response.bodyString(), UploadInfo.class); if (authInfo.domain != null && !authInfo.domain.isEmpty()) { putRet.domain = authInfo.domain; } if (authInfo.limit > 0) { callback(qq, putRet); } return putRet; }
Example 9
Source File: QiNiuUploadFileTemplateServiceImpl.java From plumemo with Apache License 2.0 | 5 votes |
@Override public String doSaveFileStore(final MultipartFile file) { final Configuration cfg = new Configuration(Zone.autoZone()); final UploadManager uploadManager = new UploadManager(cfg); final Auth auth = Auth.create(ConfigCache.getConfig(Constants.QINIU_ACCESS_KEY), ConfigCache.getConfig(Constants.QINIU_SECRET_KEY)); final String upToken = auth.uploadToken(ConfigCache.getConfig(Constants.QINIU_BUCKET)); try { final Response response = uploadManager.put(file.getInputStream(), FileUtil.createSingleFileName(file.getOriginalFilename()), upToken, null, null); final DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class); return ConfigCache.getConfig(Constants.QINIU_IMAGE_DOMAIN) + putRet.key; } catch (final IOException e) { e.printStackTrace(); } return ""; }
Example 10
Source File: Configuration.java From NutzSite with Apache License 2.0 | 5 votes |
public String rsfHost(String ak, String bucket) { ZoneReqInfo zoneReqInfo = new ZoneReqInfo(ak, bucket); if (zone == null) { zone = Zone.autoZone(); } return useHttpsDomains ? zone.getRsfHttps(zoneReqInfo) : zone.getRsfHttp(zoneReqInfo); }
Example 11
Source File: Configuration.java From NutzSite with Apache License 2.0 | 5 votes |
public String rsHost(String ak, String bucket) { ZoneReqInfo zoneReqInfo = new ZoneReqInfo(ak, bucket); if (zone == null) { zone = Zone.autoZone(); } return useHttpsDomains ? zone.getRsHttps(zoneReqInfo) : zone.getRsHttp(zoneReqInfo); }
Example 12
Source File: Configuration.java From NutzSite with Apache License 2.0 | 5 votes |
public String apiHost(String ak, String bucket) { ZoneReqInfo zoneReqInfo = new ZoneReqInfo(ak, bucket); if (zone == null) { zone = Zone.autoZone(); } return useHttpsDomains ? zone.getApiHttps(zoneReqInfo) : zone.getApiHttp(zoneReqInfo); }
Example 13
Source File: Configuration.java From NutzSite with Apache License 2.0 | 5 votes |
public String ioHost(String ak, String bucket) { ZoneReqInfo zoneReqInfo = new ZoneReqInfo(ak, bucket); if (zone == null) { zone = Zone.autoZone(); } return useHttpsDomains ? zone.getIovipHttps(zoneReqInfo) : zone.getIovipHttp(zoneReqInfo); }
Example 14
Source File: Configuration.java From NutzSite with Apache License 2.0 | 5 votes |
public String upHostBackup(String upToken) throws QiniuException { ZoneReqInfo zoneReqInfo = new ZoneReqInfo(upToken); if (zone == null) { zone = Zone.autoZone(); } return useHttpsDomains ? zone.getUpBackupHttps(zoneReqInfo) : zone.getUpBackupHttp(zoneReqInfo); }
Example 15
Source File: Configuration.java From NutzSite with Apache License 2.0 | 5 votes |
public String upHost(String upToken) throws QiniuException { ZoneReqInfo zoneReqInfo = new ZoneReqInfo(upToken); if (zone == null) { zone = Zone.autoZone(); } return useHttpsDomains ? zone.getUpHttps(zoneReqInfo) : zone.getUpHttp(zoneReqInfo); }
Example 16
Source File: QiNiuCloudAutoConfiguration.java From magic-starter with GNU Lesser General Public License v3.0 | 4 votes |
@Bean @ConditionalOnMissingBean(com.qiniu.storage.Configuration.class) public com.qiniu.storage.Configuration qnConfiguration() { return new com.qiniu.storage.Configuration(Zone.autoZone()); }
Example 17
Source File: QiniuCloudStorageService.java From sdb-mall with Apache License 2.0 | 4 votes |
private void init(){ uploadManager = new UploadManager(new Configuration(Zone.autoZone())); token = Auth.create(config.getQiniuAccessKey(), config.getQiniuSecretKey()). uploadToken(config.getQiniuBucketName()); }
Example 18
Source File: QiniuCloudStorageService.java From renren-fast with GNU General Public License v3.0 | 4 votes |
private void init(){ uploadManager = new UploadManager(new Configuration(Zone.autoZone())); token = Auth.create(config.getQiniuAccessKey(), config.getQiniuSecretKey()). uploadToken(config.getQiniuBucketName()); }