本文整理汇总了Java中com.qiniu.storage.UploadManager类的典型用法代码示例。如果您正苦于以下问题:Java UploadManager类的具体用法?Java UploadManager怎么用?Java UploadManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UploadManager类属于com.qiniu.storage包,在下文中一共展示了UploadManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configUploadEnv
import com.qiniu.storage.UploadManager; //导入依赖的package包/类
/**
* 配置文件上传环境
*/
public boolean configUploadEnv(String zone, String bucket) {
if (!checkNet()) {
Platform.runLater(() -> {
Dialogs.showError(Values.NET_ERROR);
System.exit(0);
});
return false;
}
logger.info("config file upload environment");
// 构造一个带指定Zone对象的配置类
Configuration configuration = new Configuration(QiniuApplication.zone.get(zone));
// 生成上传凭证,然后准备上传
String localTempDir = Paths.get(QiniuApplication.workDir, bucket).toString();
try {
FileRecorder fileRecorder = new FileRecorder(localTempDir);
QiniuApplication.uploadManager = new UploadManager(configuration, fileRecorder);
} catch (IOException e1) {
logger.error("load local temp directory failed, can't use file recorder");
QiniuApplication.uploadManager = new UploadManager(configuration);
}
QiniuApplication.configuration = configuration;
QiniuApplication.bucketManager = new BucketManager(QiniuApplication.auth, configuration);
return true;
}
示例2: afterPropertiesSet
import com.qiniu.storage.UploadManager; //导入依赖的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.storage.UploadManager; //导入依赖的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.storage.UploadManager; //导入依赖的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: UploadUtil
import com.qiniu.storage.UploadManager; //导入依赖的package包/类
public UploadUtil(String accessKey, String secertKEY, String bucketName) {
mAccessKey = accessKey;
mSecertKey = secertKEY;
mBucketName = bucketName;
mAuth = Auth.create(mAccessKey, mSecertKey);
mUploadManager = new UploadManager();
}
示例6: upload
import com.qiniu.storage.UploadManager; //导入依赖的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;
}
示例7: qiniuUpload
import com.qiniu.storage.UploadManager; //导入依赖的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;
}
示例8: QiniuProvider
import com.qiniu.storage.UploadManager; //导入依赖的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);
}
示例9: getUrl
import com.qiniu.storage.UploadManager; //导入依赖的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;
}
示例10: UploadUtil
import com.qiniu.storage.UploadManager; //导入依赖的package包/类
public UploadUtil(String accessKey, String secertKEY, String bucketName) {
mAccessKey = accessKey;
mSecertKey = secertKEY;
mBucketName = bucketName;
mAuth = Auth.create(mAccessKey, mSecertKey);
mUploadManager = new UploadManager();
}
示例11: QiNiuKit
import com.qiniu.storage.UploadManager; //导入依赖的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();
}
示例12: upload
import com.qiniu.storage.UploadManager; //导入依赖的package包/类
/**
* 普通文件上传
*
* @param uploadFile 待上传的文件路径
* @param fileName 文件名称
* @return the cloud file url
* @throws QiniuException exception
*/
public String upload(String uploadFile, String fileName) throws QiniuException {
Assert.notNull(uploadFile);
Assert.notNull(fileName);
UploadManager uploadManager = new UploadManager();
Response res = uploadManager.put(uploadFile, fileName, getUpToken());
LOGGER.info("upload file,uploadFile={}, fileName={}, response={}", uploadFile, fileName, res.bodyString());
return generateFileUrl(fileName);
}
示例13: QiniuBucket
import com.qiniu.storage.UploadManager; //导入依赖的package包/类
QiniuBucket(String bucket, String domain, Auth auth, BucketManager bm){
this.bucket = bucket;
this.auth = auth;
this.bucketManager = bm;
this.domain = domain;
uploadManager = new UploadManager();
}
示例14: init
import com.qiniu.storage.UploadManager; //导入依赖的package包/类
private void init(){
uploadManager = new UploadManager(new Configuration(Zone.autoZone()));
token = Auth.create(config.getQiniuAccessKey(), config.getQiniuSecretKey()).
uploadToken(config.getQiniuBucketName());
}
示例15: init
import com.qiniu.storage.UploadManager; //导入依赖的package包/类
private void init() {
uploadManager = new UploadManager(new Configuration(Zone.autoZone()));
token = Auth.create(config.getQiniuAccessKey(), config.getQiniuSecretKey()).
uploadToken(config.getQiniuBucketName());
}