Search in sources :

Example 1 with UploadManager

use of com.qiniu.storage.UploadManager in project paascloud-master by paascloud.

the class QiniuOssConfiguration method uploadManager.

/**
 * Upload manager upload manager.
 *
 * @return the upload manager
 */
@Bean
public UploadManager uploadManager() {
    Zone zone = Zone.autoZone();
    // 创建上传对象
    UploadManager uploadManager = new UploadManager(new com.qiniu.storage.Configuration(zone));
    log.info("Create UploadManager OK.");
    return uploadManager;
}
Also used : Zone(com.qiniu.common.Zone) UploadManager(com.qiniu.storage.UploadManager) Bean(org.springframework.context.annotation.Bean)

Example 2 with UploadManager

use of com.qiniu.storage.UploadManager 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 {
            log.warn(r.bodyString());
            return r.bodyString();
        } catch (QiniuException ex2) {
        // ignore
        }
    }
    return null;
}
Also used : Response(com.qiniu.http.Response) QiniuException(com.qiniu.common.QiniuException) 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)

Aggregations

UploadManager (com.qiniu.storage.UploadManager)2 Gson (com.google.gson.Gson)1 QiniuException (com.qiniu.common.QiniuException)1 Zone (com.qiniu.common.Zone)1 Response (com.qiniu.http.Response)1 Configuration (com.qiniu.storage.Configuration)1 DefaultPutRet (com.qiniu.storage.model.DefaultPutRet)1 Auth (com.qiniu.util.Auth)1 Bean (org.springframework.context.annotation.Bean)1