2025年7月7日16:01:26

master
zhangmeng 2025-07-07 16:01:33 +08:00
parent 6d95eeed3c
commit 2a4583d6e0
3 changed files with 31 additions and 8 deletions

View File

@ -100,6 +100,8 @@ public class MinioController {
@FXML
public TableColumn<BucketFile, String> file_bucket;
public ImageView preview;
public TextField upload_path_dir;
private File upload_file;
@ -253,9 +255,13 @@ public class MinioController {
AlertUtils.alert_warning("请选择上传的文件后再试!");
return;
}
MinioUtils.upload_file(upload_file);
String objectUrl = MinioUtils.getPresignedObjectUrl(bucket_name.getText(), upload_file.getName());
preview.setImage(new javafx.scene.image.Image(objectUrl));
String uri = MinioUtils.upload_file(upload_file, upload_path_dir.getText());
if (uri != null){
String bucketName = backet_list.getSelectionModel().getSelectedItem();
loadPreview(bucketName,uri);
reload();
}
});
bucket_btn.setOnAction(event -> {

View File

@ -203,6 +203,21 @@ public class MinioUtils {
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();

View File

@ -17,7 +17,7 @@
<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">
<children>
<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="151.0">
<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">
<columns>
<TableColumn fx:id="file_bucket" prefWidth="300.0" text="bucket名称" />
<TableColumn fx:id="file_name" prefWidth="270.0" text="文件名称" />
@ -31,12 +31,14 @@
<Label layoutX="23.0" layoutY="58.0" text="backetList :" />
<ComboBox fx:id="backet_list" layoutX="112.0" layoutY="52.0" prefHeight="27.0" prefWidth="346.0" />
<Label layoutX="28.0" layoutY="102.0" text="上传文件 :" />
<TextField fx:id="upload_path" layoutX="112.0" layoutY="96.0" prefHeight="27.0" prefWidth="347.0" />
<TextField fx:id="upload_path" layoutX="112.0" layoutY="96.0" prefHeight="27.0" prefWidth="346.0" />
<HBox layoutX="792.0" layoutY="6.0" />
<Button fx:id="choose_upload_file" layoutX="484.0" layoutY="99.0" mnemonicParsing="false" prefHeight="23.0" prefWidth="69.0" text="选择文件" />
<Button fx:id="upload" layoutX="571.0" layoutY="99.0" mnemonicParsing="false" prefHeight="23.0" prefWidth="58.0" text="上传" />
<ImageView fx:id="preview" fitHeight="133.0" fitWidth="211.0" layoutX="696.0" layoutY="7.0" pickOnBounds="true" preserveRatio="true" />
<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="服务器相对路径:" />
</children>
</AnchorPane>
<MenuBar prefHeight="25.0" prefWidth="240.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">