本文整理汇总了Java中com.qiniu.common.Zone类的典型用法代码示例。如果您正苦于以下问题:Java Zone类的具体用法?Java Zone怎么用?Java Zone使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Zone类属于com.qiniu.common包,在下文中一共展示了Zone类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadProperties
import com.qiniu.common.Zone; //导入依赖的package包/类
/**
* 加载配置文件并配置密钥()
*/
public static void loadProperties() throws MythException {
InputStream in = QiNiuCloud.class.getClassLoader().getResourceAsStream("qiniu.properties");
Properties pro = new Properties();
try{
pro.load(in);//加载配置文件
}catch(IOException e){
throw new MythException(PROPERTIES_EXCEPTION,e,QiNiuCloud.class);
}
accessKey = pro.getProperty("accessKey");//加载ACCESS_KEY
secretKey = pro.getProperty("secretKey");//加载SECRET_KEY
bucketName = pro.getProperty("bucketName");//加载要上传的空间名
qiniuLink = pro.getProperty("qiniuLink");//加载七牛空间外链
auth = Auth.create(accessKey, secretKey);//密钥配置
zone = Zone.autoZone();//指定上传的Zone的信息
config = new Configuration(zone);
}
示例2: afterPropertiesSet
import com.qiniu.common.Zone; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
Configuration cfg = new Configuration(Zone.zone0());
cfg.connectTimeout=5000;
cfg.responseTimeout=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();
}
示例3: QiniuProvider
import com.qiniu.common.Zone; //导入依赖的package包/类
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 z = Zone.autoZone();
Configuration c = new Configuration(z);
uploadManager = new UploadManager(c);
bucketManager = new BucketManager(auth,c);
this.isPrivate = isPrivate;
}
示例4: load
import com.qiniu.common.Zone; //导入依赖的package包/类
public void load() {
cfg = new Configuration(Zone.autoZone());
auth = Auth.create(Config.getInstance().getQiniuAccessKey(),
Config.getInstance().getQiniuSecretKey());
bucketManager = new BucketManager(auth, cfg);
uploadManager = new UploadManager(cfg);
uploadData = new HashMap<>();
uploadPool = Executors.newFixedThreadPool(10);
}
示例5: upload
import com.qiniu.common.Zone; //导入依赖的package包/类
/**
* 上传图片到七牛云
*/
public static String upload(InputStream is){
//构造一个带指定Zone对象的配置类
Configuration cfg = new Configuration(Zone.zone0());
//...其他参数参考类注释
UploadManager uploadManager = new UploadManager(cfg);
//...生成上传凭证,然后准备上传
String accessKey = "vuQFyN34wj9OjD3P_iy4vUsJVSE_VaaOOf0damQ4";
String secretKey = "2TfV9P_Jz4Wj415OaN4ErAADskCA0U-WBiFP52VW";
String link = "http://omoitwcai.bkt.clouddn.com/";
String bucket = "zhizhonghwang-pic";
//默认不指定key的情况下,以文件内容的hash值作为文件名
String key = null;
try {
Auth auth = Auth.create(accessKey, secretKey);
String upToken = auth.uploadToken(bucket);
Response response = uploadManager.put(is, key, upToken, null, null);
//解析上传成功的结果
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
link = link+putRet.hash;
} catch (QiniuException ex) {
Response r = ex.response;
System.err.println(r.toString());
link = "http://omoitwcai.bkt.clouddn.com/2017-07-21-%E9%BB%98%E8%AE%A4.jpg";
try {
System.err.println(r.bodyString());
} catch (QiniuException ex2) {
//ignore
}
}
return link;
}
示例6: qiniuUpload
import com.qiniu.common.Zone; //导入依赖的package包/类
public static String qiniuUpload(String filePath){
//构造一个带指定Zone对象的配置类 zone2华南
Configuration cfg = new Configuration(Zone.zone2());
UploadManager uploadManager = new UploadManager(cfg);
String localFilePath = filePath;
//默认不指定key的情况下,以文件内容的hash值作为文件名
String key = null;
Auth auth = Auth.create(accessKey, secretKey);
String upToken = auth.uploadToken(bucket);
try {
Response response = uploadManager.put(localFilePath, key, upToken);
//解析上传成功的结果
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
return origin+putRet.key;
}catch(QiniuException ex){
Response r = ex.response;
log.warn(r.toString());
try {
log.warn(r.bodyString());
return r.bodyString();
} catch (QiniuException ex2) {
//ignore
}
}
return null;
}
示例7: QiniuProvider
import com.qiniu.common.Zone; //导入依赖的package包/类
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);
}
示例8: getUrl
import com.qiniu.common.Zone; //导入依赖的package包/类
public static String getUrl(String filePath){
String accessKey = "7td20cUlG7ws09BauAA9XXljJHJGx9ynEZYaRrTx";
String secretKey = "nXD2rtQcHMHNxD4_sVDWrlodYhXW59XCuIDu9xiQ";
String bucket = "photoscript";
String cname = "http://owh91v0g1.bkt.clouddn.com/";
Configuration cfg = new Configuration(Zone.zone0());
UploadManager uploadManager = new UploadManager(cfg);
Auth auth = Auth.create(accessKey, secretKey);
String upToken = auth.uploadToken(bucket);
String url = null;
try {
Response response = uploadManager.put(filePath, null, upToken);
//解析上传成功的结果
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
url = cname+putRet.key;
} catch (QiniuException ex) {
Response r = ex.response;
System.err.println(r.toString());
try {
System.err.println(r.bodyString());
} catch (QiniuException ignored) {
}
}
return url;
}
示例9: init
import com.qiniu.common.Zone; //导入依赖的package包/类
private void init(){
uploadManager = new UploadManager(new Configuration(Zone.autoZone()));
token = Auth.create(config.getQiniuAccessKey(), config.getQiniuSecretKey()).
uploadToken(config.getQiniuBucketName());
}
示例10: initZone
import com.qiniu.common.Zone; //导入依赖的package包/类
public void initZone() {
zone.put(Values.BUCKET_NAME_ARRAY[0], Zone.zone0());
zone.put(Values.BUCKET_NAME_ARRAY[1], Zone.zone1());
zone.put(Values.BUCKET_NAME_ARRAY[2], Zone.zone2());
zone.put(Values.BUCKET_NAME_ARRAY[3], Zone.zoneNa0());
}
示例11: init
import com.qiniu.common.Zone; //导入依赖的package包/类
private void init() {
uploadManager = new UploadManager(new Configuration(Zone.autoZone()));
token = Auth.create(config.getQiniuAccessKey(), config.getQiniuSecretKey()).
uploadToken(config.getQiniuBucketName());
}
示例12: uploadResource
import com.qiniu.common.Zone; //导入依赖的package包/类
/**
* 上传资源的最主要方法
* 参数依次的含义: 点播云空间名(对应portal-->点播空间左上角的名字),失效时间,上传文件类型(参考文档),要上传的文件路径(最好用绝对路径)
* StringMap (params参数)可以put进 key, crc32, x:vod, accept, xvod 这些值进去
*/
public Map<String, Object> uploadResource(String hub, int deadline, String type, String path, Map<String, Object> params) {
if (type == null || type.length() <= 0) {
type = "video";
}
UptokenRet uptokenRet = getVodUptokenV2(hub, deadline, type);
// 判空,能否获取token
if (uptokenRet == null) {
System.err.println("cann't get vod uptoken");
return null;
}
Configuration cf = new Configuration(Zone.autoZone());
// 创建上传对象
UploadManager uploadManager = new UploadManager(cf);
Map<String, Object> ret = new HashMap<String, Object>();
try {
// key 参数为空,则用uptokenRet里的key
String k = uptokenRet.getKey();
if (params.containsKey("key")) {
k = params.get("key").toString();
params.remove("key");
}
boolean checkCrc=false;
if (params.containsKey("crc32")){
checkCrc=(Boolean) params.get("crc32");
params.remove("crc32");
}
// 调用put方法上传
StringMap qparams=new StringMap();
qparams.putAll(params);
Response res=uploadManager.put(path,k,uptokenRet.getUptoken(),qparams,null,checkCrc);
// 打印返回的信息
System.out.println(res.bodyString());
StringMap retMap = res.jsonToMap();
ret.put("code", res.statusCode);
ret.put("hash", retMap.get("hash"));
ret.put("key", retMap.get("key"));
} catch (QiniuException e) {
Response r = e.response;
// 请求失败时,返回错误码,由客户自己根据错误码,在前端显示相应的提示信息
ret.put("code", r.statusCode);
ret.put("msg", r.toString()); // 错误信息
System.err.printf("upload file error:%s",e.toString());
}
return ret;
}