Search in sources :

Example 6 with CUploadResult

use of com.mendmix.cos.CUploadResult in project jeesuite-libs by vakinge.

the class QiniuProvider method upload.

@Override
public CUploadResult upload(CUploadObject object) {
    String fileKey = object.getFileKey();
    String bucketName = buildBucketName(object.getBucketName());
    try {
        Response res = null;
        String upToken = getUpToken(bucketName);
        if (object.getFile() != null) {
            res = uploadManager.put(object.getFile(), fileKey, upToken);
        } else if (object.getBytes() != null) {
            res = uploadManager.put(object.getBytes(), fileKey, upToken);
        } else if (object.getInputStream() != null) {
            res = uploadManager.put(object.getInputStream(), fileKey, upToken, null, object.getMimeType());
        } else {
            throw new IllegalArgumentException("upload object is NULL");
        }
        if (res.isOK()) {
            return new CUploadResult(fileKey, getFullPath(object.getBucketName(), fileKey), null);
        }
    } catch (QiniuException e) {
        processQiniuException(object.getFileKey(), e);
    }
    return null;
}
Also used : Response(com.qiniu.http.Response) CUploadResult(com.mendmix.cos.CUploadResult) QiniuException(com.qiniu.common.QiniuException)

Aggregations

CUploadResult (com.mendmix.cos.CUploadResult)6 JeesuiteBaseException (com.mendmix.common.JeesuiteBaseException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 CObjectMetadata (com.mendmix.cos.CObjectMetadata)3 InputStream (java.io.InputStream)2 OSSException (com.aliyun.oss.OSSException)1 ObjectMetadata (com.aliyun.oss.model.ObjectMetadata)1 PutObjectRequest (com.aliyun.oss.model.PutObjectRequest)1 PutObjectResult (com.aliyun.oss.model.PutObjectResult)1 AccessControlList (com.obs.services.model.AccessControlList)1 ObjectMetadata (com.obs.services.model.ObjectMetadata)1 PutObjectResult (com.obs.services.model.PutObjectResult)1 CosServiceException (com.qcloud.cos.exception.CosServiceException)1 ObjectMetadata (com.qcloud.cos.model.ObjectMetadata)1 PutObjectRequest (com.qcloud.cos.model.PutObjectRequest)1 PutObjectResult (com.qcloud.cos.model.PutObjectResult)1 Upload (com.qcloud.cos.transfer.Upload)1 QiniuException (com.qiniu.common.QiniuException)1 Response (com.qiniu.http.Response)1 ObjectWriteResponse (io.minio.ObjectWriteResponse)1