|
|
@@ -1,3 +1,4 @@
|
|
|
+import cn.reghao.oss.api.constant.UploadChannel;
|
|
|
import cn.reghao.oss.api.rest.UploadFileRet;
|
|
|
import cn.reghao.oss.sdk.ObjectMultipartUploadService;
|
|
|
import cn.reghao.oss.sdk.ObjectUploadService;
|
|
|
@@ -12,29 +13,21 @@ import java.io.*;
|
|
|
@Slf4j
|
|
|
public class ObjectTest {
|
|
|
static final String endpoint = "https://oss.reghao.cn";
|
|
|
-
|
|
|
- static void upload() {
|
|
|
- ObjectUploadService objectUploadService = new ObjectUploadService(endpoint);
|
|
|
- String filePath = "/home/reghao/Downloads/sxd.mp4";
|
|
|
- filePath = "/home/reghao/Downloads/1.txt";
|
|
|
- File file = new File(filePath);
|
|
|
-
|
|
|
- long userId = 10020;
|
|
|
- for (; userId < 10250; userId++) {
|
|
|
- UploadFileRet uploadFileRet = objectUploadService.postObject(file, 1, userId);
|
|
|
- //UploadFileRet uploadFileRet = objectUploadService.putObject(file, 1, userId);
|
|
|
- if (uploadFileRet == null) {
|
|
|
- log.error("文件上传失败");
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
+ static ObjectUploadService objectUploadService = new ObjectUploadService(endpoint);
|
|
|
+
|
|
|
+ static void upload(File file) {
|
|
|
+ long userId = 10001;
|
|
|
+ UploadFileRet uploadFileRet = objectUploadService.postObject(file, UploadChannel.video.getCode(), userId);
|
|
|
+ //UploadFileRet uploadFileRet = objectUploadService.putObject(file, 1, userId);
|
|
|
+ if (uploadFileRet == null) {
|
|
|
+ log.info("文件上传失败");
|
|
|
+ } else {
|
|
|
log.info("{} -> {}", uploadFileRet.getUploadId(), uploadFileRet.getUrl());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void multipartUpload() throws Exception {
|
|
|
ObjectMultipartUploadService multipartUploadService = new ObjectMultipartUploadService(endpoint);
|
|
|
-
|
|
|
String filePath = "/home/reghao/Downloads/abc.mp4";
|
|
|
int channelId = 1;
|
|
|
multipartUploadService.upload(new File(filePath), channelId);
|
|
|
@@ -43,6 +36,9 @@ public class ObjectTest {
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- upload();
|
|
|
+ String filePath = "/home/reghao/Downloads/sxd.mp4";
|
|
|
+ //filePath = "/home/reghao/Downloads/1.txt";
|
|
|
+ File file = new File(filePath);
|
|
|
+ upload(file);
|
|
|
}
|
|
|
}
|