| | |
| | | static String bucketName = "";
|
| | | static COSClient cosClient;
|
| | | static String totalBucketName = "";
|
| | | static String accessHost = "";
|
| | |
|
| | | static COSManager instance;
|
| | |
|
| | |
| | | cosClient = new COSClient(cred, clientConfig);
|
| | | // bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式
|
| | | totalBucketName = bucketName + "-" + appId;
|
| | | accessHost = params.getAccessHost();
|
| | | }
|
| | |
|
| | | public FileUploadResult uploadFile(File f, String key) {
|
| | |
| | | try {
|
| | | PutObjectResult result = cosClient.putObject(putObjectRequest);
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(accessHost)) {
|
| | | return new FileUploadResult(String.format("http://%s.file.myqcloud.com%s", totalBucketName, key),
|
| | | result.getETag());
|
| | | } else {
|
| | | return new FileUploadResult(String.format("%s%s", accessHost, key),
|
| | | result.getETag());
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|