本文整理汇总了Java中com.qiniu.util.Auth类的典型用法代码示例。如果您正苦于以下问题:Java Auth类的具体用法?Java Auth怎么用?Java Auth使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Auth类属于com.qiniu.util包,在下文中一共展示了Auth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: qiniuBase64Upload
import com.qiniu.util.Auth; //导入依赖的package包/类
public static String qiniuBase64Upload(String data64){
String key = renamePic(".png");
Auth auth = Auth.create(accessKey, secretKey);
String upToken = auth.uploadToken(bucket);
//服务端http://up-z2.qiniup.com
String url = "http://up-z2.qiniup.com/putb64/-1/key/"+ UrlSafeBase64.encodeToString(key);
RequestBody rb = RequestBody.create(null, data64);
Request request = new Request.Builder().
url(url).
addHeader("Content-Type", "application/octet-stream")
.addHeader("Authorization", "UpToken " + getUpToken())
.post(rb).build();
System.out.println(request.headers());
OkHttpClient client = new OkHttpClient();
okhttp3.Response response = null;
try {
response = client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(response);
return origin+key;
}
示例2: loadProperties
import com.qiniu.util.Auth; //导入依赖的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);
}
示例3: afterPropertiesSet
import com.qiniu.util.Auth; //导入依赖的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();
}
示例4: QiniuProvider
import com.qiniu.util.Auth; //导入依赖的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;
}
示例5: start
import com.qiniu.util.Auth; //导入依赖的package包/类
@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);
}
AUTH = Auth.create(CONFIG.getConf(null, QiniuConfig.AK),
CONFIG.getConf(null, QiniuConfig.SK));
LOG.info("QiniuService start successfully!");
} catch (Exception e) {
LOG.error("QiniuService start error -> {}", e.getMessage());
}
}
示例6: load
import com.qiniu.util.Auth; //导入依赖的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);
}
示例7: UploadUtil
import com.qiniu.util.Auth; //导入依赖的package包/类
public UploadUtil(String accessKey, String secertKEY, String bucketName) {
mAccessKey = accessKey;
mSecertKey = secertKEY;
mBucketName = bucketName;
mAuth = Auth.create(mAccessKey, mSecertKey);
mUploadManager = new UploadManager();
}
示例8: upload
import com.qiniu.util.Auth; //导入依赖的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;
}
示例9: qiniuUpload
import com.qiniu.util.Auth; //导入依赖的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;
}
示例10: QiniuProvider
import com.qiniu.util.Auth; //导入依赖的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);
}
示例11: getUrl
import com.qiniu.util.Auth; //导入依赖的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;
}
示例12: Hdfs2Qiniu
import com.qiniu.util.Auth; //导入依赖的package包/类
public Hdfs2Qiniu(Config uploadCfg, int worker) throws IOException, NoSuchAlgorithmException {
Configuration cfg = new Configuration();
String[] hdfsCfgs = uploadCfg.hdfsConfigs.split(",");
for (String xml : hdfsCfgs) {
cfg.addResource(new Path("file://" + xml.trim()));
}
this.hdfsFileSystem = FileSystem.get(cfg);
this.uploadCfg = uploadCfg;
this.worker = worker;
this.auth = Auth.create(this.uploadCfg.accessKey, this.uploadCfg.secretKey);
this.initLogging();
}
示例13: UploadUtil
import com.qiniu.util.Auth; //导入依赖的package包/类
public UploadUtil(String accessKey, String secertKEY, String bucketName) {
mAccessKey = accessKey;
mSecertKey = secertKEY;
mBucketName = bucketName;
mAuth = Auth.create(mAccessKey, mSecertKey);
mUploadManager = new UploadManager();
}
示例14: QiNiuKit
import com.qiniu.util.Auth; //导入依赖的package包/类
public QiNiuKit() {
this.accessKey = Config.QINIU_ACCESSKEY;
this.secretKey = Config.QINIU_SECRETKEY;
this.domain = Config.QINIU_DOMAIN;
this.bucketName = Config.QINIU_BUCKETNAME;
this.auth = Auth.create(this.accessKey, this.secretKey);
//this.key = UUID.randomUUID().toString();
this.uploadManager = new UploadManager();
}
示例15: Qiniu
import com.qiniu.util.Auth; //导入依赖的package包/类
public Qiniu(String accessKey, String secretKey, String space, String domain) {
this.accessKey = accessKey;
this.secretKey = secretKey;
this.space = space;
this.domain = domain;
this.auth = Auth.create(accessKey, secretKey);
}