ossFile.setOriginalName(file.getOriginalFilename());
return new OssUploadResult(ossFile.geteTag() == null ? Constant.FAILURE : Constant.SUCCESS, ossFile);
}
private OssFile ossUpload(String key, InputStream inputStream, ObjectMetadata metadata) {
OssFile result = null;
try {
PutObjectResult putObjectResult = ossClient.putObject(bucket, key, inputStream, metadata);
result = new OssFile(putObjectResult.getETag());
result.setUrl(endpoint + Constant.SLASH + bucket + Constant.SLASH + key);
result.setSize(metadata.getContentLength());
result.setContentType(metadata.getContentType());
} catch (OSSException e) {
result = new OssFile(e.getErrorCode(), e.getMessage());
e.printStackTrace();
} catch (ClientException e) {
result = new OssFile(null, e.getMessage());
e.printStackTrace();
}
return result;
}