package com.dcsoft.file.controller;

import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class test {
    public static void main(String[] args) throws Exception {
        MinIO minIO = new MinIO("http://192.168.124.185:9000","minioadmin","minioadmin");
        String bucket = "visitor";
        //一、上传文件：
        //将file转化为MultipartFile （图片在项目的resources目录下，必须将文件转化为为MultipartFile类型）
//        File file = new File("src/main/resources/img.png");
//        FileInputStream fileInputStream = new FileInputStream(file);
//        MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getName(),
//                MediaType.IMAGE_PNG_VALUE //PNG类型的图片，所以用这个枚举。点击MediaType有对应类型
//                , fileInputStream);
//        String url = minIO.upload(multipartFile, bucket);//上传
//        System.out.println("上传之后的URL为："+url);
        //二、删除刚刚上传的图片：
        String fileName = "/insurancePolicy1/1FUe3OV4yKlD41feaef8ea19ed5e94c0749d84dc749320240529153149A026.pdf";
        minIO.delete(bucket,fileName);
    }
}
