Compare commits

...

4 Commits

Author SHA1 Message Date
zhangmeng e2b534901d 2025年7月7日17:26:16 2025-07-07 17:26:20 +08:00
zhangmeng d13072c819 2025年7月7日17:11:20 2025-07-07 17:11:26 +08:00
zhangmeng 2a4583d6e0 2025年7月7日16:01:26 2025-07-07 16:01:33 +08:00
zhangmeng 6d95eeed3c 2025年7月7日15:32:03 2025-07-07 15:32:10 +08:00
13 changed files with 366 additions and 289 deletions

View File

@ -1,3 +0,0 @@
endpoint = http://192.168.1.254:9000
accessKey = minioadmin
secretKey = minioadmin

78
pom.xml
View File

@ -18,25 +18,7 @@
<dependency> <dependency>
<groupId>io.minio</groupId> <groupId>io.minio</groupId>
<artifactId>minio</artifactId> <artifactId>minio</artifactId>
<version>8.5.7</version> <version>8.5.17</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.8.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency> </dependency>
<dependency> <dependency>
@ -83,59 +65,41 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.leewyatt</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>rxcontrols</artifactId> <artifactId>fastjson2</artifactId>
<!-- 11.x.y --> <version>2.0.49</version>
<version>11.0.2</version>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>1.27</version> <!-- 请检查并使用最新版本 -->
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<!-- 使用maven-jar-plugin和maven-dependency-plugin插件打包 -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.1.0</version> <version>3.11.0</version>
<configuration> <configuration>
<archive> <source>17</source>
<manifest> <target>17</target>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.zhangmeng.minio.MiniToolsApplication</mainClass>
</manifest>
</archive>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.openjfx</groupId>
<artifactId>maven-dependency-plugin</artifactId> <artifactId>javafx-maven-plugin</artifactId>
<version>3.1.1</version> <version>0.0.8</version>
<executions> <executions>
<execution> <execution>
<id>copy-dependencies</id> <!-- Default configuration for running with: mvn clean javafx:run -->
<phase>package</phase> <id>default-cli</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration> <configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory> <mainClass>com.zhangmeng.minio.MiniToolsApplication
</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>

View File

@ -5,6 +5,7 @@ import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -18,9 +19,15 @@ public class MiniToolsApplication extends Application {
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
MinioUtils.objectMap.put(MinioUtils.primaryStage,primaryStage); MinioUtils.objectMap.put(MinioUtils.primaryStage,primaryStage);
Parent root = FXMLLoader.load(this.getClass().getResource("/fxml/main.fxml")); AnchorPane root = FXMLLoader.load(this.getClass().getResource("/fxml/main.fxml"));
primaryStage.setScene(new Scene(root)); primaryStage.setScene(new Scene(root));
primaryStage.setTitle("javafx minio 工具"); primaryStage.setTitle("javafx minio 工具");
primaryStage.show(); primaryStage.show();
} }
public static void main(String[] args) {
launch(args);
}
} }

View File

@ -1,15 +0,0 @@
package com.zhangmeng.minio;
import javafx.application.Application;
/**
* @author zhangmeng
* @version 1.0
* @date 2024-03-11 16:44
*/
public class Start {
public static void main(String[] args) {
Application.launch(MiniToolsApplication.class,args);
}
}

View File

@ -0,0 +1,22 @@
package com.zhangmeng.minio.controller;
import javafx.event.ActionEvent;
import javafx.scene.control.TextField;
public class ConfigController {
public TextField url;
public TextField username;
public TextField password;
public void initialize() {
}
public void handleSave(ActionEvent actionEvent) {
}
public void handleCancel(ActionEvent actionEvent) {
}
}

View File

@ -1,10 +1,14 @@
package com.zhangmeng.minio.controller; package com.zhangmeng.minio.controller;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONPObject;
import com.zhangmeng.minio.model.BucketFile; import com.zhangmeng.minio.model.BucketFile;
import com.zhangmeng.minio.model.Config;
import com.zhangmeng.minio.utils.AlertUtils; import com.zhangmeng.minio.utils.AlertUtils;
import com.zhangmeng.minio.utils.MinioUtils; import com.zhangmeng.minio.utils.MinioUtils;
import com.zhangmeng.minio.utils.ResourceUtils; import com.zhangmeng.minio.utils.ResourceUtils;
import io.minio.messages.Bucket; import io.minio.messages.Bucket;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
@ -14,11 +18,14 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination; import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination; import javafx.scene.input.KeyCombination;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import javafx.stage.Modality;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.awt.Toolkit; import java.awt.Toolkit;
@ -29,8 +36,11 @@ import java.awt.datatransfer.Transferable;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.CompletableFuture;
/** /**
* @author zhangmeng * @author zhangmeng
@ -68,18 +78,12 @@ public class MinioController {
@FXML @FXML
public Button bucket_btn; public Button bucket_btn;
@FXML
public TextField endpoint; public TextField endpoint;
@FXML
public TextField accessKey; public TextField accessKey;
@FXML
public TextField secretKey; public TextField secretKey;
@FXML
public Button save_config;
@FXML @FXML
public ComboBox<String> backet_list; public ComboBox<String> backet_list;
@ -98,11 +102,20 @@ public class MinioController {
@FXML @FXML
public TableColumn<BucketFile, String> file_bucket; public TableColumn<BucketFile, String> file_bucket;
public ImageView preview;
public TextField upload_path_dir;
public Button connect_server;
private File upload_file; private File upload_file;
@FXML @FXML
public void initialize() { public void initialize() {
endpoint = new TextField();
accessKey = new TextField();
secretKey = new TextField();
tableview.setItems(list); tableview.setItems(list);
file_name.setCellValueFactory(new PropertyValueFactory<BucketFile, String>("fileName")); file_name.setCellValueFactory(new PropertyValueFactory<BucketFile, String>("fileName"));
file_size.setCellValueFactory(new PropertyValueFactory<BucketFile, Number>("size")); file_size.setCellValueFactory(new PropertyValueFactory<BucketFile, Number>("size"));
@ -122,13 +135,10 @@ public class MinioController {
BucketFile selectedItem = tableview.getSelectionModel().getSelectedItem(); BucketFile selectedItem = tableview.getSelectionModel().getSelectedItem();
// 获取系统剪贴板 // 获取系统剪贴板
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
// 创建一个 StringSelection 对象,该对象封装了要复制的文本 // 创建一个 StringSelection 对象,该对象封装了要复制的文本
Transferable transferableText = new StringSelection(selectedItem.getUrl()); Transferable transferableText = new StringSelection(selectedItem.getUrl());
// 将文本内容设置到剪贴板 // 将文本内容设置到剪贴板
clipboard.setContents(transferableText, null); clipboard.setContents(transferableText, null);
@ -154,7 +164,7 @@ public class MinioController {
@Override @Override
public void changed(ObservableValue<? extends BucketFile> observable, BucketFile oldValue, BucketFile newValue) { public void changed(ObservableValue<? extends BucketFile> observable, BucketFile oldValue, BucketFile newValue) {
if (newValue != null) { if (newValue != null) {
System.out.println(newValue.getFileName()); loadPreview(backet_list.getSelectionModel().getSelectedItem(), newValue.getFileName());
} }
} }
}); });
@ -166,19 +176,35 @@ public class MinioController {
FileInputStream fileInputStream = null; FileInputStream fileInputStream = null;
try { try {
FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getResource("/fxml/config.fxml")); FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getResource("/fxml/config.fxml"));
AnchorPane root = fxmlLoader.load(); VBox root = fxmlLoader.load();
ObservableMap<String, Object> namespace = fxmlLoader.getNamespace(); ObservableMap<String, Object> namespace = fxmlLoader.getNamespace();
TextArea text_area = (TextArea) namespace.get("text_area"); TextField url = (TextField) namespace.get("url");
Button save_p = (Button) namespace.get("save_p"); TextField username = (TextField) namespace.get("username");
TextField password = (TextField) namespace.get("password");
Button save = (Button) namespace.get("save");
Button cancel = (Button) namespace.get("cancel");
fileInputStream = new FileInputStream(ResourceUtils.getPropertiesFile()); fileInputStream = new FileInputStream(ResourceUtils.getPropertiesFile());
byte[] bytes = fileInputStream.readAllBytes(); byte[] bytes = fileInputStream.readAllBytes();
text_area.setText(new String(bytes, StandardCharsets.UTF_8)); String json = new String(bytes, StandardCharsets.UTF_8);
Stage stage = AlertUtils.alert("minio 配置文件", root, 600, 410, (Stage) MinioUtils.objectMap.get(MinioUtils.primaryStage)); if (json != null && !json.equals("")) {
save_p.setOnAction(event1 -> { Config parseObject = JSON.parseObject(json, Config.class);
endpoint.setText(parseObject.getEndpoint());
url.setText(parseObject.getEndpoint());
accessKey.setText(parseObject.getAccessKey());
username.setText(parseObject.getAccessKey());
secretKey.setText(parseObject.getSecretKey());
password.setText(parseObject.getSecretKey());
}
Stage stage = AlertUtils.alert("minio 配置文件", root, 600, 180, (Stage) MinioUtils.objectMap.get(MinioUtils.primaryStage));
save.setOnAction(event1 -> {
stage.close(); stage.close();
try { try {
FileWriter fileWriter = new FileWriter(ResourceUtils.getPropertiesFile()); FileWriter fileWriter = new FileWriter(ResourceUtils.getPropertiesFile());
fileWriter.write(text_area.getText()); Config config = new Config(endpoint.getText(), accessKey.getText(), secretKey.getText());
String json_config = JSON.toJSONString(config);
fileWriter.write(json_config);
fileWriter.flush(); fileWriter.flush();
fileWriter.close(); fileWriter.close();
load_property(); load_property();
@ -232,9 +258,13 @@ public class MinioController {
AlertUtils.alert_warning("请选择上传的文件后再试!"); AlertUtils.alert_warning("请选择上传的文件后再试!");
return; return;
} }
String uri = MinioUtils.upload_file(upload_file, upload_path_dir.getText());
MinioUtils.upload_file(upload_file); if (uri != null) {
String bucketName = backet_list.getSelectionModel().getSelectedItem();
loadPreview(bucketName, uri);
reload(); reload();
}
}); });
bucket_btn.setOnAction(event -> { bucket_btn.setOnAction(event -> {
@ -261,20 +291,20 @@ public class MinioController {
load_bucket_list(); load_bucket_list();
}); });
load_property();
save_config.setOnAction(event -> save_properties());
backet_list.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() { backet_list.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
@Override @Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (newValue != null) { if (newValue != null && !newValue.equals("")) {
MinioUtils.objectMap.put(MinioUtils.current_bucket, newValue); MinioUtils.objectMap.put(MinioUtils.current_bucket, newValue);
reload(); reload();
} }
} }
}); });
backet_list.setItems(backet_item_list); backet_list.setItems(backet_item_list);
connect_server.setOnAction(event -> {
load_property();
});
} }
public void save_properties() { public void save_properties() {
@ -331,53 +361,67 @@ public class MinioController {
} }
} }
private void loadPreview(String bucketName, String objectName) {
String objectUrl = MinioUtils.getPresignedObjectUrl(bucketName, objectName);
preview.setImage(new javafx.scene.image.Image(objectUrl));
}
public void load_bucket_list() { public void load_bucket_list() {
//刷新bucket列表 //刷新bucket列表
//获取所有储存桶 //获取所有储存桶
backet_item_list.clear(); backet_item_list.clear();
List<Bucket> buckets = MinioUtils.getAllBuckets(); List<Bucket> buckets = MinioUtils.getAllBuckets();
if (buckets != null) {
Platform.runLater(() -> {
if (buckets.size() > 0) { if (buckets.size() > 0) {
for (Bucket bucket : buckets) { for (Bucket bucket : buckets) {
backet_item_list.add(bucket.name()); backet_item_list.add(bucket.name());
} }
} }
this.backet_list.getSelectionModel().select(bucket_name.getText()); this.backet_list.getSelectionModel().select(bucket_name.getText());
});
}
} }
public void load_property() { public void load_property() {
Properties prop = new Properties();
File file = ResourceUtils.getPropertiesFile(); File file = ResourceUtils.getPropertiesFile();
if (file != null) { if (file != null) {
InputStream input = null;
try { try {
input = new FileInputStream(file); String json = Files.readString(file.toPath());
// load a properties file Config config = JSON.parseObject(json, Config.class);
prop.load(input); this.endpoint.setText(config.getEndpoint());
// get the property value and print it out this.accessKey.setText(config.getAccessKey());
String endpoint = prop.getProperty("endpoint"); this.secretKey.setText(config.getSecretKey());
this.endpoint.setText(endpoint); MinioUtils.objectMap.put("endpoint", config.getEndpoint());
String accessKey = prop.getProperty("accessKey"); MinioUtils.objectMap.put("accessKey", config.getAccessKey());
this.accessKey.setText(accessKey); MinioUtils.objectMap.put("secretKey", config.getSecretKey());
String secretKey = prop.getProperty("secretKey");
this.secretKey.setText(secretKey);
MinioUtils.objectMap.put("endpoint", endpoint);
MinioUtils.objectMap.put("accessKey", accessKey);
MinioUtils.objectMap.put("secretKey", secretKey);
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} finally { }
if (input != null) { }
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
try { try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
load_bucket_list(); load_bucket_list();
return "success";
} catch (Exception e) {
return "failure";
}
});
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.initModality(Modality.APPLICATION_MODAL);
alert.setContentText("正在尝试连接服务器...");
alert.setHeaderText(null);
// 去掉右上角的关闭按钮
alert.setOnCloseRequest(event -> alert.close());
alert.show();
future.whenComplete((result, ex) -> {
Platform.runLater(alert::close);
});
} }
@FXML @FXML

View File

@ -0,0 +1,47 @@
package com.zhangmeng.minio.model;
public class Config {
private String endpoint;
private String accessKey;
private String secretKey;
public Config(String endpoint, String accessKey, String secretKey) {
this.endpoint = endpoint;
this.accessKey = accessKey;
this.secretKey = secretKey;
}
@Override
public String toString() {
return "Config{" +
"endpoint='" + endpoint + '\'' +
", accessKey='" + accessKey + '\'' +
", secretKey='" + secretKey + '\'' +
'}';
}
public String getEndpoint() {
return endpoint;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
public String getAccessKey() {
return accessKey;
}
public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}
public String getSecretKey() {
return secretKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
}

View File

@ -7,10 +7,7 @@ import io.minio.http.Method;
import io.minio.messages.Bucket; import io.minio.messages.Bucket;
import io.minio.messages.Item; import io.minio.messages.Item;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.scene.control.TextField;
import org.apache.commons.lang3.StringUtils;
import org.apache.tika.Tika;
import org.apache.tika.exception.TikaException;
import java.io.*; import java.io.*;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
@ -32,8 +29,6 @@ public class MinioUtils {
private static MinioClient minioClient = null; private static MinioClient minioClient = null;
public static Map<String,Object> objectMap = new HashMap<>(); public static Map<String,Object> objectMap = new HashMap<>();
public static String current_bucket = "current_bucket"; public static String current_bucket = "current_bucket";
public static String primaryStage = "primaryStage"; public static String primaryStage = "primaryStage";
@ -77,24 +72,11 @@ public class MinioUtils {
public static List<Bucket> getAllBuckets() { public static List<Bucket> getAllBuckets() {
try { try {
return getDefault().listBuckets(); return getDefault().listBuckets();
} catch (ErrorResponseException e) { } catch (ErrorResponseException | InsufficientDataException | InvalidKeyException | InternalException | InvalidResponseException | IOException | NoSuchAlgorithmException | ServerException | XmlParserException e) {
e.printStackTrace(); // e.printStackTrace();
} catch (InsufficientDataException e) { Platform.runLater(()->{
e.printStackTrace(); AlertUtils.alert_warning("获取Bucket列表失败,请核对配置信息");
} catch (InternalException e) { });
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (InvalidResponseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (ServerException e) {
e.printStackTrace();
} catch (XmlParserException e) {
e.printStackTrace();
} }
return null; return null;
} }
@ -109,23 +91,7 @@ public class MinioUtils {
if (!bucketExists(bucketName)) { if (!bucketExists(bucketName)) {
try { try {
getDefault().makeBucket(MakeBucketArgs.builder().bucket(bucketName).build()); getDefault().makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
} catch (ErrorResponseException e) { } catch (ErrorResponseException | InternalException | InvalidKeyException | InvalidResponseException | IOException | NoSuchAlgorithmException | XmlParserException | ServerException | InsufficientDataException e) {
e.printStackTrace();
} catch (InsufficientDataException e) {
e.printStackTrace();
} catch (InternalException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (InvalidResponseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (ServerException e) {
e.printStackTrace();
} catch (XmlParserException e) {
e.printStackTrace(); e.printStackTrace();
} }
}else { }else {
@ -144,23 +110,7 @@ public class MinioUtils {
public static Boolean bucketExists(String bucketName) { public static Boolean bucketExists(String bucketName) {
try { try {
return getDefault().bucketExists(BucketExistsArgs.builder().bucket(bucketName).build()); return getDefault().bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
} catch (ErrorResponseException e) { } catch (ErrorResponseException | InsufficientDataException | InternalException | InvalidResponseException | NoSuchAlgorithmException | XmlParserException | ServerException | IOException | InvalidKeyException e) {
e.printStackTrace();
} catch (InsufficientDataException e) {
e.printStackTrace();
} catch (InternalException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (InvalidResponseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (ServerException e) {
e.printStackTrace();
} catch (XmlParserException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
@ -192,23 +142,9 @@ public class MinioUtils {
Item item = null; Item item = null;
try { try {
item = o.get(); item = o.get();
} catch (ErrorResponseException e) { } catch (ErrorResponseException | InsufficientDataException | InvalidKeyException |
e.printStackTrace(); InvalidResponseException | InternalException | IOException | NoSuchAlgorithmException |
} catch (InsufficientDataException e) { ServerException | XmlParserException e) {
e.printStackTrace();
} catch (InternalException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (InvalidResponseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (ServerException e) {
e.printStackTrace();
} catch (XmlParserException e) {
e.printStackTrace(); e.printStackTrace();
} }
list.add(item); list.add(item);
@ -231,23 +167,7 @@ public class MinioUtils {
.method(Method.GET).build(); .method(Method.GET).build();
try { try {
return getDefault() .getPresignedObjectUrl(args); return getDefault() .getPresignedObjectUrl(args);
} catch (ErrorResponseException e) { } catch (ErrorResponseException | InsufficientDataException | InvalidKeyException | InvalidResponseException | NoSuchAlgorithmException | ServerException | XmlParserException | IOException | InternalException e) {
e.printStackTrace();
} catch (InsufficientDataException e) {
e.printStackTrace();
} catch (InternalException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (InvalidResponseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (XmlParserException e) {
e.printStackTrace();
} catch (ServerException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
@ -275,7 +195,7 @@ public class MinioUtils {
public static void upload_file(File file){ public static void upload_file(File file){
//文件名 //文件名
String fileName = file.getName(); String fileName = file.getName();
String newFileName = System.currentTimeMillis() + "." + StringUtils.substringAfterLast(fileName, "."); String newFileName = System.currentTimeMillis() + "." + getFileExtension(fileName);
String contentType = getContentType(file); String contentType = getContentType(file);
String bucketName = objectMap.get(current_bucket).toString(); String bucketName = objectMap.get(current_bucket).toString();
if (bucketName == null){ if (bucketName == null){
@ -285,6 +205,92 @@ public class MinioUtils {
uploadFile(bucketName, file, newFileName, contentType); uploadFile(bucketName, file, newFileName, contentType);
} }
public static String upload_file(File file,String path){
//文件名
String fileName = file.getName();
String newFileName = System.currentTimeMillis() + "." + getFileExtension(fileName);
String contentType = getContentType(file);
String bucketName = objectMap.get(current_bucket).toString();
if (bucketName == null){
AlertUtils.alert_warning("上传的bucket不能为空!");
return null;
}
uploadFile(bucketName, file, path + "/" + newFileName, contentType);
return path + "/" + newFileName;
}
public static String getContentType(File file) {
String fileName = file.getName();
String extension = getFileExtension(fileName).toLowerCase();
return switch (extension) {
case "jpg", "jpeg" -> "image/jpeg";
case "png" -> "image/png";
case "mp4" -> "video/mp4";
case "gif" -> "image/gif";
case "txt" -> "text/plain";
case "pdf" -> "application/pdf";
case "doc" -> "application/msword";
case "docx" -> "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
case "xls" -> "application/vnd.ms-excel";
case "xlsx" -> "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
case "ppt" -> "application/vnd.ms-powerpoint";
case "pptx" -> "application/vnd.openxmlformats-officedocument.presentationml.presentation";
case "zip" -> "application/zip";
case "tar" -> "application/x-tar";
case "json" -> "application/json";
case "html" -> "text/html";
case "css" -> "text/css";
case "js" -> "application/javascript";
case "mp3" -> "audio/mp3";
case "wav" -> "audio/wav";
case "flac" -> "audio/flac";
case "aac" -> "audio/aac";
case "ogg" -> "audio/ogg";
case "avi" -> "video/avi";
case "mov" -> "video/quicktime";
case "wmv" -> "video/x-ms-wmv";
case "mkv" -> "video/x-matroska";
case "flv" -> "video/x-flv";
case "swf" -> "application/x-shockwave-flash";
case "psd" -> "image/vnd.adobe.photoshop";
case "ai" -> "application/postscript";
case "eps" -> "application/postscript";
case "ps" -> "application/postscript";
case "svg" -> "image/svg+xml";
case "tif" -> "image/tiff";
case "tiff" -> "image/tiff";
case "ico" -> "image/x-icon";
case "md" -> "text/markdown";
case "yaml" -> "text/yaml";
case "yml" -> "text/yaml";
case "xml" -> "text/xml";
case "csv" -> "text/csv";
case "tsv" -> "text/tab-separated-values";
case "jsonl" -> "application/json-seq";
case "bin" -> "application/octet-stream";
case "exe" -> "application/octet-stream";
case "dll" -> "application/octet-stream";
case "so" -> "application/octet-stream";
case "class" -> "application/octet-stream";
case "war" -> "application/octet-stream";
case "ear" -> "application/octet-stream";
case "rar" -> "application/octet-stream";
case "gz" -> "application/gzip";
default -> "application/octet-stream";
};
}
// 原生 Java 的等价方法
public static String getFileExtension(String fileName) {
if (fileName == null) return "";
int lastDotIndex = fileName.lastIndexOf('.');
// 判断没有点,或者点是第一个字符(例如 ".gitignore"
if (lastDotIndex == -1 || lastDotIndex == 0) {
return fileName;
}
return fileName.substring(lastDotIndex + 1);
}
/** /**
* 使MultipartFile * 使MultipartFile
* *
@ -305,23 +311,7 @@ public class MinioUtils {
.contentType(contentType) .contentType(contentType)
.stream(inputStream,inputStream.available(), -1) .stream(inputStream,inputStream.available(), -1)
.build()); .build());
} catch (IOException e) { } catch (IOException | XmlParserException | InternalException | InvalidKeyException | ErrorResponseException | ServerException | InsufficientDataException | InvalidResponseException | NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (ServerException e) {
e.printStackTrace();
} catch (InsufficientDataException e) {
e.printStackTrace();
} catch (ErrorResponseException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (InvalidResponseException e) {
e.printStackTrace();
} catch (XmlParserException e) {
e.printStackTrace();
} catch (InternalException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (inputStream != null){ if (inputStream != null){
@ -334,15 +324,4 @@ public class MinioUtils {
} }
return null; return null;
} }
public static String getContentType(File file){
Tika tika = new Tika();
try {
return tika.detect(file);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
} }

View File

@ -11,14 +11,13 @@ import java.io.IOException;
*/ */
public class ResourceUtils { public class ResourceUtils {
/** /**
* Properties prop = new Properties(); * Properties prop = new Properties();
* URL resource = this.getClass().getResource("/minio.properties"); * URL resource = this.getClass().getResource("/minio.properties");
*/ */
public static File getPropertiesFile(){ public static File getPropertiesFile(){
String file_path = System.getProperty("user.dir") + "/minio.properties"; String file_path = System.getProperty("user.dir") + "/minio.json";
File file = new File(file_path); File file = new File(file_path);
if (!file.exists()){ if (!file.exists()){
try { try {

View File

@ -0,0 +1,17 @@
module javafx.tools.minio {
requires javafx.controls;
requires javafx.fxml;
requires java.sql;
requires java.datatransfer;
requires java.desktop;
requires minio;
requires com.fasterxml.jackson.core;
requires com.alibaba.fastjson2;
opens com.zhangmeng.minio to javafx.graphics;
opens com.zhangmeng.minio.controller to javafx.fxml;
exports com.zhangmeng.minio.controller;
exports com.zhangmeng.minio.model;
}

View File

@ -1,17 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.*?>
<?import javafx.scene.control.TextArea?> <?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.geometry.Insets?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="323.0" prefWidth="600.0" style="-fx-border-width: 0;-fx-font-size: 14" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1"> <VBox spacing="10" xmlns:fx="http://javafx.com/fxml"
<children> fx:controller="com.zhangmeng.minio.controller.ConfigController">
<TextArea fx:id="text_area" layoutX="100.0" layoutY="80.0" prefHeight="255.0" prefWidth="600.0" style="-fx-border-width: 0;-fx-focus-color: null" AnchorPane.bottomAnchor="68.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" /> <padding>
<Button fx:id="save_p" layoutX="269.0" layoutY="271.0" mnemonicParsing="false" prefHeight="20.0" prefWidth="62.0" text="确定" AnchorPane.bottomAnchor="22.0"> <Insets top="10" right="10" bottom="10" left="10"/>
<font> </padding>
<Font size="15.0" />
</font> <GridPane hgap="10" vgap="10">
</Button> <columnConstraints>
</children> <ColumnConstraints minWidth="80" prefWidth="100"/>
</AnchorPane> <ColumnConstraints hgrow="ALWAYS"/>
</columnConstraints>
<Label text="minio服务器地址:" GridPane.rowIndex="0" GridPane.columnIndex="0"/>
<TextField fx:id="url" GridPane.rowIndex="0" GridPane.columnIndex="1"/>
<Label text="用户名:" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
<TextField fx:id="username" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
<!-- 描述 -->
<Label text="密码:" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
<TextField fx:id="password" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
</GridPane>
<HBox spacing="10" alignment="CENTER_RIGHT">
<Button fx:id="save" text="保存" onAction="#handleSave" defaultButton="true"/>
<Button fx:id="cancel" text="取消" onAction="#handleCancel" cancelButton="true"/>
</HBox>
</VBox>

View File

@ -9,22 +9,15 @@
<?import javafx.scene.control.TableColumn?> <?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?> <?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?> <?import javafx.scene.control.TextField?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<AnchorPane prefHeight="649" prefWidth="1200" stylesheets="@../css/main.css" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.minio.controller.MinioController"> <AnchorPane prefHeight="649" prefWidth="1200" stylesheets="@../css/main.css" xmlns="http://javafx.com/javafx/23.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.minio.controller.MinioController">
<children> <children>
<AnchorPane fx:id="center" layoutY="25.0" prefHeight="623.0" prefWidth="1200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="25.0"> <AnchorPane fx:id="center" layoutY="13.0" prefHeight="623.0" prefWidth="1200.0" AnchorPane.bottomAnchor="12.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="13.0">
<children> <children>
<Label layoutX="57.0" layoutY="53.0" text="endpoint :" /> <TableView fx:id="tableview" layoutX="378.0" layoutY="191.0" prefHeight="433.0" prefWidth="1200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="191.0">
<Label layoutX="55.0" layoutY="119.0" text="accessKey :" />
<Label layoutX="56.0" layoutY="181.0" text="secretKey :" />
<TextField fx:id="endpoint" layoutX="143.0" layoutY="49.0" prefHeight="23.0" prefWidth="207.0" />
<TextField fx:id="accessKey" layoutX="143.0" layoutY="115.0" prefHeight="23.0" prefWidth="207.0" />
<TextField fx:id="secretKey" layoutX="143.0" layoutY="177.0" prefHeight="23.0" prefWidth="207.0" />
<ComboBox fx:id="backet_list" layoutX="500.0" layoutY="114.0" prefHeight="25.0" prefWidth="207.0" />
<Label layoutX="391.0" layoutY="119.0" text="backetList :" />
<Button fx:id="save_config" layoutX="215.0" layoutY="233.0" mnemonicParsing="false" text="保存配置" />
<TableView fx:id="tableview" layoutX="378.0" layoutY="277.0" prefHeight="347.0" prefWidth="1200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="277.0">
<columns> <columns>
<TableColumn fx:id="file_bucket" prefWidth="300.0" text="bucket名称" /> <TableColumn fx:id="file_bucket" prefWidth="300.0" text="bucket名称" />
<TableColumn fx:id="file_name" prefWidth="270.0" text="文件名称" /> <TableColumn fx:id="file_name" prefWidth="270.0" text="文件名称" />
@ -33,13 +26,20 @@
</columns> </columns>
</TableView> </TableView>
<Label layoutX="391.0" layoutY="53.0" text="createBucket :" /> <Label layoutX="14.0" layoutY="16.0" text="createBucket :" />
<TextField fx:id="bucket_name" layoutX="500.0" layoutY="49.0" /> <TextField fx:id="bucket_name" layoutX="111.0" layoutY="10.0" prefHeight="27.0" prefWidth="348.0" />
<Button fx:id="bucket_btn" layoutX="677.0" layoutY="49.0" mnemonicParsing="false" text="创建bucket" /> <Label layoutX="23.0" layoutY="58.0" text="backetList :" />
<Label layoutX="394.0" layoutY="181.0" text="上传文件 :" /> <ComboBox fx:id="backet_list" layoutX="112.0" layoutY="52.0" prefHeight="27.0" prefWidth="346.0" />
<TextField fx:id="upload_path" layoutX="500.0" layoutY="177.0" prefHeight="23.0" prefWidth="207.0" /> <Label layoutX="28.0" layoutY="102.0" text="上传文件 :" />
<Button fx:id="upload" layoutX="792.0" layoutY="177.0" mnemonicParsing="false" text="上传" /> <TextField fx:id="upload_path" layoutX="112.0" layoutY="96.0" prefHeight="27.0" prefWidth="346.0" />
<Button fx:id="choose_upload_file" layoutX="717.0" layoutY="177.0" mnemonicParsing="false" text="选择文件" /> <HBox layoutX="792.0" layoutY="6.0" />
<Button fx:id="choose_upload_file" layoutX="484.0" layoutY="98.0" mnemonicParsing="false" prefHeight="23.0" prefWidth="69.0" text="选择文件" />
<Button fx:id="upload" layoutX="484.0" layoutY="135.0" mnemonicParsing="false" prefHeight="23.0" prefWidth="58.0" text="上传" />
<ImageView fx:id="preview" fitHeight="133.0" fitWidth="211.0" layoutX="955.0" layoutY="13.0" pickOnBounds="true" preserveRatio="true" />
<Button fx:id="bucket_btn" layoutX="484.0" layoutY="11.0" mnemonicParsing="false" text="创建bucket" />
<TextField fx:id="upload_path_dir" layoutX="112.0" layoutY="135.0" prefHeight="27.0" prefWidth="346.0" />
<Label layoutX="15.0" layoutY="141.0" text="服务器相对路径:" />
<Button fx:id="connect_server" layoutX="609.0" layoutY="75.0" mnemonicParsing="false" prefHeight="43.0" prefWidth="117.0" text="连接服务器" />
</children> </children>
</AnchorPane> </AnchorPane>
<MenuBar prefHeight="25.0" prefWidth="240.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"> <MenuBar prefHeight="25.0" prefWidth="240.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">

View File

@ -1,3 +0,0 @@
endpoint = http://192.168.1.254:9000
accessKey = minioadmin
secretKey = minioadmin