@Override public void upload(File file, String path) throws Exception { if(!path.startsWith("/")) { path = "/" + path; } COSClient cosClient = new COSClient(qcloudConfig.getAppId(), qcloudConfig.getSecretId(), qcloudConfig.getSecretKey()); UploadFileRequest uploadFileRequest = new UploadFileRequest(qcloudConfig.getBucket(), path, file.getPath()); String response = cosClient.uploadFile(uploadFileRequest); JSONObject jsonObject = new JSONObject(response); if(jsonObject.getInt("code") != 0) { throw new RuntimeException("上传文件异常: " + jsonObject.getString("message")); } }
@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; }
@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 = JSON.parseObject(response); if(jsonObject.getIntValue("code") != 0) { throw new RRException("文件上传失败," + jsonObject.getString("message")); } return config.getQcloudDomain() + path; }
@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.fromObject(response); if(jsonObject.getInt("code") != 0) { throw new RRException("文件上传失败," + jsonObject.getString("message")); } return config.getQcloudDomain() + path; }
@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.fromObject(response); if(jsonObject.getInt("code") != 0) { throw new RRException("文件上传失败," + jsonObject.getString("message")); } return config.getQcloudDomain() + path; }
new UploadFileRequest(bucketName, cosFilePath, localFilePath1); uploadFileRequest.setEnableShaDigest(false); String uploadFileRet = cosClient.uploadFile(uploadFileRequest); System.out.println("upload file ret:" + uploadFileRet); UploadFileRequest overWriteFileRequest = new UploadFileRequest(bucketName, cosFilePath, contentBuffer); String overWriteFileRet = cosClient.uploadFile(overWriteFileRequest); System.out.println("overwrite file ret:" + overWriteFileRet);