use of com.qcloud.cos.exception.CosServiceException in project Tbed by Hello-hao.
the class COSImageupload method ImageuploadCOS.
public ReturnImage ImageuploadCOS(Map<String, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
File file = null;
Map<ReturnImage, Integer> ImgUrl = new HashMap<>();
try {
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
String ShortUID = SetText.getShortUuid();
file = entry.getValue();
try {
String bucketName = key.getBucketname();
String userkey = username + "/" + ShortUID + "." + entry.getKey();
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, userkey, file);
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
returnImage.setImgname(userkey);
returnImage.setImgurl(key.getRequestAddress() + "/" + userkey);
returnImage.setImgSize(entry.getValue().length());
returnImage.setCode("200");
} catch (CosServiceException serverException) {
returnImage.setCode("400");
serverException.printStackTrace();
} catch (CosClientException clientException) {
returnImage.setCode("400");
clientException.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
returnImage.setCode("500");
}
return returnImage;
}
use of com.qcloud.cos.exception.CosServiceException in project alluxio by Alluxio.
the class COSInputStream method createStream.
@Override
protected InputStream createStream(long startPos, long endPos) throws IOException {
GetObjectRequest req = new GetObjectRequest(mBucketName, mKey);
// COS returns entire object if we read past the end
req.setRange(startPos, endPos < mContentLength ? endPos - 1 : mContentLength - 1);
CosServiceException lastException = null;
String errorMessage = String.format("Failed to open key: %s bucket: %s", mKey, mBucketName);
while (mRetryPolicy.attempt()) {
try {
COSObject object = mCosClient.getObject(req);
return new BufferedInputStream(object.getObjectContent());
} catch (CosServiceException e) {
errorMessage = String.format("Failed to open key: %s bucket: %s attempts: %d error: %s", mKey, mBucketName, mRetryPolicy.getAttemptCount(), e.getMessage());
if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND) {
throw new IOException(errorMessage, e);
}
// Key does not exist
lastException = e;
}
}
// Failed after retrying key does not exist
throw new IOException(errorMessage, lastException);
}
Aggregations