|
|
@@ -0,0 +1,88 @@
|
|
|
+import cn.reghao.oss.api.constant.ObjectAction;
|
|
|
+import cn.reghao.oss.api.dto.ServerInfo;
|
|
|
+import cn.reghao.oss.api.dto.UploadedFile;
|
|
|
+import cn.reghao.oss.api.dto.rest.UploadFileRet;
|
|
|
+import cn.reghao.oss.sdk.OssClient;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.file.*;
|
|
|
+import java.nio.file.attribute.BasicFileAttributes;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author reghao
|
|
|
+ * @date 2023-06-02 16:19:04
|
|
|
+ */
|
|
|
+public class OssClientTest {
|
|
|
+ public void startWalk(String baseDir) throws IOException {
|
|
|
+ Path path = Paths.get(baseDir);
|
|
|
+ walkDir(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ void walkDir(Path path) throws IOException {
|
|
|
+ Files.walkFileTree(path, new FileVisitor<>() {
|
|
|
+ @Override
|
|
|
+ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
|
|
+ File dir1 = dir.toFile();
|
|
|
+ return FileVisitResult.CONTINUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
|
|
+ processFile("", "", file.toFile());
|
|
|
+ return FileVisitResult.CONTINUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
|
|
|
+ return FileVisitResult.CONTINUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
|
|
+ return FileVisitResult.CONTINUE;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ void processFile(String uploadUrl, String uploadToken, File file) {
|
|
|
+ String filePath = file.getAbsolutePath();
|
|
|
+ try {
|
|
|
+ String filename = file.getName();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
+ String endpoint = "http://localhost:8010";
|
|
|
+ String ak = "PmvonhHI";
|
|
|
+ String sk = "28aQEK7wJ6U5m7E1u7";
|
|
|
+ OssClient ossClient = new OssClient(endpoint, ak, sk);
|
|
|
+
|
|
|
+ ServerInfo serverInfo = ossClient.getServerInfo();
|
|
|
+ String uploadUrl = serverInfo.getOssUrl();
|
|
|
+ String uploadToken = serverInfo.getToken();
|
|
|
+
|
|
|
+ String baseDir = "/home/reghao/Downloads/1";
|
|
|
+ //client.startWalk(baseDir);
|
|
|
+ /*String filePath = "/home/reghao/Downloads/abc.mp4";
|
|
|
+ File file = new File(filePath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ System.out.printf("%s not exist\n", filePath);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ UploadFileRet uploadFileRet = ossClient.uploadFilePart(uploadUrl, uploadToken, Path.of(filePath));
|
|
|
+ if (uploadFileRet != null) {
|
|
|
+ System.out.printf("uploadId -> %s\n", uploadFileRet.getUploadId());
|
|
|
+ }*/
|
|
|
+
|
|
|
+ File file = new File("");
|
|
|
+ UploadFileRet uploadFileRet = ossClient.postObject(file);
|
|
|
+
|
|
|
+ String objectId = "653ee234e1964cfda3578efbe1e7d0b0";
|
|
|
+ String signedUrl = ossClient.getSignedUrl(objectId, ObjectAction.access.getName());
|
|
|
+ System.out.printf("signed url -> %s\n", signedUrl);
|
|
|
+ }
|
|
|
+}
|