Search in sources :

Example 16 with Auth

use of com.qiniu.util.Auth in project xmall by Exrick.

the class QiniuUtil method qiniuUpload.

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 {
            return r.bodyString();
        } catch (QiniuException e) {
            throw new XmallUploadException(e.toString());
        }
    }
}
Also used : Response(com.qiniu.http.Response) QiniuException(com.qiniu.common.QiniuException) XmallUploadException(cn.exrick.common.exception.XmallUploadException) Configuration(com.qiniu.storage.Configuration) Auth(com.qiniu.util.Auth) Gson(com.google.gson.Gson) DefaultPutRet(com.qiniu.storage.model.DefaultPutRet) UploadManager(com.qiniu.storage.UploadManager)

Example 17 with Auth

use of com.qiniu.util.Auth in project paascloud-master by paascloud.

the class QiniuOssConfiguration method auth.

/**
 * Auth auth.
 *
 * @return the auth
 */
@Bean
public Auth auth() {
    Auth auth = Auth.create(paascloudProperties.getQiniu().getKey().getAccessKey(), paascloudProperties.getQiniu().getKey().getSecretKey());
    log.info("Create Auth OK.");
    return auth;
}
Also used : Auth(com.qiniu.util.Auth) Bean(org.springframework.context.annotation.Bean)

Example 18 with Auth

use of com.qiniu.util.Auth in project alluxio by Alluxio.

the class KodoUnderFileSystem method creatInstance.

protected static KodoUnderFileSystem creatInstance(AlluxioURI uri, UnderFileSystemConfiguration conf) {
    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.getString(PropertyKey.KODO_ACCESS_KEY);
    String secretKey = conf.getString(PropertyKey.KODO_SECRET_KEY);
    String endPoint = conf.getString(PropertyKey.KODO_ENDPOINT);
    String souceHost = conf.getString(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);
}
Also used : Builder(okhttp3.OkHttpClient.Builder) OkHttpClient(okhttp3.OkHttpClient) UnderFileSystemConfiguration(alluxio.underfs.UnderFileSystemConfiguration) Configuration(com.qiniu.storage.Configuration) Auth(com.qiniu.util.Auth)

Aggregations

Auth (com.qiniu.util.Auth)18 JSONObject (org.json.JSONObject)10 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)8 Configuration (com.qiniu.storage.Configuration)7 After (org.b3log.latke.servlet.annotation.After)7 Before (org.b3log.latke.servlet.annotation.Before)7 AbstractFreeMarkerRenderer (org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer)7 UploadManager (com.qiniu.storage.UploadManager)6 Response (com.qiniu.http.Response)4 QiniuException (com.qiniu.common.QiniuException)3 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3 ServiceException (org.b3log.latke.service.ServiceException)3 XmallUploadException (cn.exrick.common.exception.XmallUploadException)2 Gson (com.google.gson.Gson)2 DefaultPutRet (com.qiniu.storage.model.DefaultPutRet)2 OkHttpClient (okhttp3.OkHttpClient)2 JSONArray (org.json.JSONArray)2 UnderFileSystemConfiguration (alluxio.underfs.UnderFileSystemConfiguration)1 BucketManager (com.qiniu.storage.BucketManager)1