|
|
@@ -1,132 +0,0 @@
|
|
|
-package me.zhengjie.base.util;
|
|
|
-
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.net.URL;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.UUID;
|
|
|
-import io.minio.MinioClient;
|
|
|
-import io.minio.PutObjectOptions;
|
|
|
-import io.minio.messages.Bucket;
|
|
|
-import net.coobird.thumbnailator.Thumbnails;
|
|
|
-
|
|
|
-public class A {
|
|
|
-// public static void main(String[] args) throws IOException {
|
|
|
-// // show();
|
|
|
-// HashMap<String, String> map = new HashMap<>();
|
|
|
-// map.put("aaa", "bbb");
|
|
|
-// Thread.currentThread().sleep(millis);
|
|
|
-// }
|
|
|
- private static void printWithThread(String content) {
|
|
|
- System.out.println("[" + Thread.currentThread().getName() + "线程]: " + content);
|
|
|
- }
|
|
|
-
|
|
|
- public static void main(String[] args) {
|
|
|
- // show();
|
|
|
- String str = "https://124.222.192.60:9000/mytest/no10020220609164946793/APP387702301847479292.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20220614%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220614T060036Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=a04e0d1ad2241753ba4007a3b292f3acb767143de99c4705e043c7c1a2de01c7";
|
|
|
- int index = str.indexOf( "/",8);
|
|
|
- System.out.println(str.substring(index));;
|
|
|
-// printWithThread("开始执行main方法");
|
|
|
-//
|
|
|
-// Thread myThread = new Thread(() -> {
|
|
|
-// printWithThread("我在自定义的线程的run方法里");
|
|
|
-// printWithThread("我马上要休息1秒钟, 并让出CPU给别的线程使用.");
|
|
|
-// try {
|
|
|
-// Thread.sleep(100000000l);
|
|
|
-// printWithThread("已经休息了1秒, 又重新获得了CPU");
|
|
|
-// printWithThread("我休息好了, 马上就退出了");
|
|
|
-// } catch (InterruptedException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-//
|
|
|
-// });
|
|
|
-// try {
|
|
|
-// myThread.start();
|
|
|
-// printWithThread("我在main方法里面, 我要等下面这个线程执行完了才能继续往下执行.");
|
|
|
-// synchronized (myThread) {
|
|
|
-// myThread.wait(0);
|
|
|
-// }
|
|
|
-// printWithThread("我在main方法里面, 马上就要退出了.");
|
|
|
-// } catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
- }
|
|
|
-
|
|
|
- public static void compress() throws IOException {
|
|
|
- String str = "E:\\SmartAdmin\\companyframework\\eladmin-master\\eladmin-system\\target\\d55b912d019f48d881847fddf722c3e7_6.jpeg";
|
|
|
- File file = new File(str);
|
|
|
-
|
|
|
- /**
|
|
|
- * 判断是否是图片 判断是否超过了 100K
|
|
|
- */
|
|
|
- if ((1024 * 1024 * 0.1) <= file.length()) {
|
|
|
- FileInputStream input = new FileInputStream(file);
|
|
|
- // 在项目根目录下的 upload 目录中生成临时文件
|
|
|
- File newFile = new File("E:\\image\\aaa.jpeg");
|
|
|
- // 小于 1M 的
|
|
|
- if ((1024 * 1024 * 0.1) <= file.length() && file.length() <= (1024 * 1024)) {
|
|
|
- Thumbnails.of(input).scale(0.3f).outputQuality(0.3f).toFile(newFile);
|
|
|
- }
|
|
|
- // 1 - 2M 的
|
|
|
- else if ((1024 * 1024) < file.length() && file.length() <= (1024 * 1024 * 2)) {
|
|
|
- Thumbnails.of(input).scale(0.2f).outputQuality(0.2f).toFile(newFile);
|
|
|
- }
|
|
|
- // 2M 以上的
|
|
|
-
|
|
|
- else if ((1024 * 1024 * 2) < file.length()) {
|
|
|
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
- // bos.in
|
|
|
- Thumbnails.of(input).scale(0.1f).toOutputStream(bos);
|
|
|
-
|
|
|
- }
|
|
|
- // 获取输入流
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public static void show() {
|
|
|
-
|
|
|
- try {
|
|
|
-
|
|
|
- String bucketName = "mytest";
|
|
|
- MinioClient minioClient = new MinioClient("http://124.222.192.60:9000", "minioadmin", "minioadmin");
|
|
|
- boolean flag = minioClient.bucketExists("mytest");
|
|
|
- System.out.println("是否存在此桶:" + flag);
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd/");
|
|
|
- String date = sdf.format(new Date());
|
|
|
- // 找一个你电脑上图片的绝对路径,最好是PNG图片
|
|
|
- File file = new File("E:\\demo\\image\\2022\\03\\18\\1f7c69d855814f829c158ded51642168.png");
|
|
|
- long size = file.length();
|
|
|
- String fileName = file.getName();
|
|
|
- InputStream is = new FileInputStream(file);
|
|
|
- // 将待上传的文件的路径设置成 年/月/日/uuid+file01.png
|
|
|
- // 你也可以自定义上传文件的路径,这样设置是为了更好的管理
|
|
|
- String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 6);
|
|
|
- String fileUploadPath = date + uuid + "file01" + fileName.substring(fileName.lastIndexOf("."));
|
|
|
-
|
|
|
- PutObjectOptions options = new PutObjectOptions(size, -1);
|
|
|
- // 设置图片的contentType,如果不是PNG图片就自行修改对应的contentType,这样做的目的是为了上传之后访问图片时可以在浏览器预览而不用下载,当然也可以注释这行代码
|
|
|
- options.setContentType("image/png");
|
|
|
-//
|
|
|
- minioClient.putObject(bucketName, fileUploadPath, is, options);
|
|
|
-//
|
|
|
-// System.out.println(file.getAbsolutePath() + "is successfully uploaded as 【" + fileUploadPath + "】 to 【"
|
|
|
-// + bucketName + "】bucket.");
|
|
|
- String aa = minioClient.presignedGetObject("mytest", "no10020220609164946793/APP387702301847479292.mp4",
|
|
|
- 604800);
|
|
|
- System.out.println(aa);
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-}
|