@Override public void delete(String keyName) { if (bucketManager == null) { if (auth == null) { auth = Auth.create(accessKey, secretKey); } bucketManager = new BucketManager(auth, new Configuration()); } try { bucketManager.delete(bucketName, keyName); } catch (Exception e) { e.printStackTrace(); } }
/** * 七牛云OSS对象存储简单上传实现 */ @Override public void store(InputStream inputStream, long contentLength, String contentType, String keyName) { if (uploadManager == null) { if (auth == null) { auth = Auth.create(accessKey, secretKey); } uploadManager = new UploadManager(new Configuration()); } try { String upToken = auth.uploadToken(bucketName); Response response = uploadManager.put(inputStream, keyName, upToken, null, contentType); } catch (QiniuException ex) { ex.printStackTrace(); } }
protected static KodoUnderFileSystem creatInstance(AlluxioURI uri, UnderFileSystemConfiguration conf, AlluxioConfiguration alluxioConf) { String bucketName = UnderFileSystemUtils.getBucketName(uri); Preconditions.checkArgument(conf.isSet(PropertyKey.KODO_ACCESS_KEY), "Property %s is required to connect to Kodo", PropertyKey.KODO_ACCESS_KEY); Preconditions.checkArgument(conf.isSet(PropertyKey.KODO_SECRET_KEY), "Property %s is required to connect to Kodo", PropertyKey.KODO_SECRET_KEY); Preconditions.checkArgument(conf.isSet(PropertyKey.KODO_DOWNLOAD_HOST), "Property %s is required to connect to Kodo", PropertyKey.KODO_DOWNLOAD_HOST); Preconditions.checkArgument(conf.isSet(PropertyKey.KODO_ENDPOINT), "Property %s is required to connect to Kodo", PropertyKey.KODO_ENDPOINT); String accessKey = conf.get(PropertyKey.KODO_ACCESS_KEY); String secretKey = conf.get(PropertyKey.KODO_SECRET_KEY); String endPoint = conf.get(PropertyKey.KODO_ENDPOINT); String souceHost = conf.get(PropertyKey.KODO_DOWNLOAD_HOST); Auth auth = Auth.create(accessKey, secretKey); Configuration configuration = new Configuration(); OkHttpClient.Builder okHttpBuilder = initializeKodoClientConfig(conf); OkHttpClient okHttpClient = okHttpBuilder.build(); KodoClient kodoClient = new KodoClient(auth, bucketName, souceHost, endPoint, configuration, okHttpClient); return new KodoUnderFileSystem(uri, kodoClient, conf, alluxioConf); }
/** * 构造一个带指定Zone对象的配置类 zone2华南 */ public Configuration getConfiguration(){ Configuration cfg = null; if(zone.equals(0)){ cfg = new Configuration(Zone.zone0()); }else if(zone.equals(1)){ cfg = new Configuration(Zone.zone1()); }else if(zone.equals(2)){ cfg = new Configuration(Zone.zone2()); }else if(zone.equals(3)){ cfg = new Configuration(Zone.zoneNa0()); }else if(zone.equals(4)){ cfg = new Configuration(Zone.zoneAs0()); }else { cfg = new Configuration(Zone.autoZone()); } return cfg; }
public String upload(MultipartFile file, String fileName) { //构造一个带指定Zone对象的配置类 Configuration cfg = new Configuration(Zone.zone0()); //...其他参数参考类注释 UploadManager uploadManager = new UploadManager(cfg); //默认不指定key的情况下,以文件内容的hash值作为文件名 String key = null; Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY); String upToken = auth.uploadToken(BUCKET); try { Response response = null; response = uploadManager.put(file.getInputStream(), fileName, upToken, null, null); //解析上传成功的结果 DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class); System.out.println(putRet.key); System.out.println(putRet.hash); return putRet.key; } catch (QiniuException ex) { Response r = ex.response; System.err.println(r.toString()); try { System.err.println(r.bodyString()); } catch (QiniuException ex2) { //ignore } } catch (IOException e) { e.printStackTrace(); } return null; }
public UploadManager(Client client, Recorder recorder) { this.client = client; this.recorder = recorder; configuration = new Configuration(); }
public OperationManager(Auth auth, Client client) { this.auth = auth; this.client = client; this.configuration = new Configuration(); }
public BucketManager(Auth auth, Client client) { this.auth = auth; this.client = client; this.configuration = new Configuration(); }
/** * 华东机房 */ @Bean public com.qiniu.storage.Configuration qiniuConfig() { return new com.qiniu.storage.Configuration(Zone.zone0()); }
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; this.host = StringUtils.remove(urlprefix,"/").split(":")[1]; }
private void init(){ uploadManager = new UploadManager(new Configuration(Zone.autoZone())); token = Auth.create(config.getQiniuAccessKey(), config.getQiniuSecretKey()). uploadToken(config.getQiniuBucketName()); }
private void init(){ uploadManager = new UploadManager(new Configuration(Zone.autoZone())); token = Auth.create(config.getQiniuAccessKey(), config.getQiniuSecretKey()). uploadToken(config.getQiniuBucketName()); }
@Before public void setUp() throws Exception { //default config Configuration cfg = new Configuration(); cfg.useHttpsDomains = false; // cfg.useHttpsDomains = true; this.bucketManager = new BucketManager(TestConfig.testAuth, cfg); //na0 config Configuration cfgNa0 = new Configuration(Zone.zoneNa0()); this.bucketManagerNa0 = new BucketManager(TestConfig.testAuth, cfgNa0); //dummy config this.dummyBucketManager = new BucketManager(TestConfig.dummyAuth, new Configuration()); }
private void init(){ uploadManager = new UploadManager(new Configuration(Zone.autoZone())); token = Auth.create(config.getQiniuAccessKey(), config.getQiniuSecretKey()). uploadToken(config.getQiniuBucketName()); }
private void init(){ uploadManager = new UploadManager(new Configuration(Zone.autoZone())); token = Auth.create(config.getQiniuAccessKey(), config.getQiniuSecretKey()). uploadToken(config.getQiniuBucketName()); }
public Response up(Zone zone) throws Exception { int i = r.nextInt(10000); try { System.out.println("UP: " + i + ", enter up"); if (recorder == null) { recorder = new FileRecorder(file.getParentFile()); } uploader = new ResumeUploader(client, token, key, file, null, Client.DefaultMime, recorder, new Configuration(zone)); Response res = uploader.upload(); System.out.println("UP: " + i + ", left up"); return res; } catch (Exception e) { System.out.println("UP: " + i + ", exception up"); throw e; } } }
public String upload(byte[] data, String path) throws Exception { try { uploadManager = new UploadManager(new Configuration(Zone.autoZone())); token = Auth.create(cloudStorageConfigPo.getQiniuAccessKey(), cloudStorageConfigPo.getQiniuSecretKey()).uploadToken(cloudStorageConfigPo.getQiniuBucketName()); Response res = uploadManager.put(data, path, token); if (!res.isOK()) { throw new RuntimeException("上传七牛出错:" + res.toString()); } } catch (Exception e) { throw new RuntimeException("上传文件失败,请核对七牛配置信息", e); } return cloudStorageConfigPo.getQiniuDomain() + "/" + path; }
@Test public void testHello2() { Map<String, Zone> bucketKeyMap = new HashMap<String, Zone>(); bucketKeyMap.put(TestConfig.testBucket_z0, Zone.zone0()); bucketKeyMap.put(TestConfig.testBucket_na0, Zone.zoneNa0()); for (Map.Entry<String, Zone> entry : bucketKeyMap.entrySet()) { String bucket = entry.getKey(); Zone zone = entry.getValue(); Configuration c = new Configuration(zone); c.useHttpsDomains = true; UploadManager uploadManager = new UploadManager(c); hello(uploadManager, bucket); } }
@Test public void testPrefopVsample() throws QiniuException { String persistentId = "z0.5b2cd03638b9f324a561e56d"; Configuration cfg = new Configuration(); //cfg.useHttpsDomains = true; OperationStatus status = new OperationManager(TestConfig.testAuth, cfg).prefop(persistentId); assertEquals(0, status.code); assertTrue("vsample prefop's keys length gt 1", status.items[0].keys.length > 1); } }
@Test public void testPrefop() { String persistentId = "na0.5899aaf692129336c2034e2d"; try { Configuration cfg = new Configuration(); //cfg.useHttpsDomains = true; OperationStatus status = new OperationManager(TestConfig.testAuth, cfg).prefop(persistentId); assertEquals(0, status.code); } catch (QiniuException ex) { Assert.assertEquals(612, ex.code()); } }