use of com.qcloud.cos.request.UploadFileRequest in project mall by wangxl-git.
the class QcloudCloudStorageService method upload.
@Override
public String upload(byte[] data, String path) {
// 腾讯云必需要以"/"开头
if (!path.startsWith("/")) {
path = "/" + path;
}
// 上传到腾讯云
UploadFileRequest request = new UploadFileRequest(config.getQcloudBucketName(), path, data);
String response = client.uploadFile(request);
JSONObject jsonObject = JSONObject.parseObject(response);
if (jsonObject.getInteger("code") != 0) {
throw new RRException("文件上传失败," + jsonObject.getString("message"));
}
return config.getQcloudDomain() + path;
}
use of com.qcloud.cos.request.UploadFileRequest in project xian by happyyangyuan.
the class CosFileWriter method forPath.
public boolean forPath(String path, String data) {
try {
checkPath(path);
// 初始化cosClient,如果没有初始化的话
getCosClient();
UploadFileRequest request = new UploadFileRequest(BUCKET, getBase() + path, data.getBytes());
request.setInsertOnly(InsertOnly.OVER_WRITE);
return doUpload(request, 3);
} catch (Throwable e) {
LOG.error(e);
return false;
}
}
use of com.qcloud.cos.request.UploadFileRequest in project xian by happyyangyuan.
the class CosFileWriter method main.
public static void main(String[] args) {
COSClient cosClient = new COSClient(10053621, "AKID5iJcsYewRYIJhqQsoaLQ7Ks1XIO6eYPs", "Gm0nqHOPzUG1MRRJnBLX4UwwQMoh8v4y");
ClientConfig config = new ClientConfig();
config.setRegion("sh");
cosClient.setConfig(config);
UploadFileRequest request = new UploadFileRequest("xian", "/xian_runtime_IDE_happyyangyuan/xian/yy/991.txt", "测试data".getBytes());
request.setInsertOnly(InsertOnly.OVER_WRITE);
String uploadFileRet = cosClient.uploadFile(request);
LOG.info("上传文件返回:" + uploadFileRet);
GetFileInputStreamRequest inputStreamRequest = new GetFileInputStreamRequest("xian", "/xian_runtime_IDE_happyyangyuan/xian/yy/991.txt");
inputStreamRequest.setUseCDN(false);
try (InputStream inputStream = cosClient.getFileInputStream(inputStreamRequest)) {
System.out.println("读文件:" + StringIO.readFully(inputStream));
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations