base64上传minio图片缺失,直接上代码

该代码示例展示了如何使用MinioJavaSDK创建一个名为demo的bucket,并将本地的PNG图片(由base64数据还原生成)上传到这个bucket中。首先,检查bucket是否存在,如果不存在则创建。然后,将图片文件读取为输入流并上传至Minio服务器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    public static void main(String[] args) throws IOException {
         String endpoint="http://127.0.0.1:9000";
         String accessKey="minioadmin";
         String secretKey="minioadmin";
        InputStream inputstream=null;
        File file=null;
        try {
            MinioClient client=new MinioClient(endpoint, accessKey, secretKey);
            if (!client.bucketExists("demo")) {
                client.makeBucket("demo");
            }
            String filename="uu4.png";
            String base64=readJsonFile();//base64数据
            ImageUtils.generateImage(base64,"C:\\Users\\Administrator\\Desktop\\1\\122.png");
            file= new File("C:\\Users\\Administrator\\Desktop\\1\\122.png");
            inputstream=new FileInputStream(file);
            client.putObject("demo", filename, inputstream, inputstream.available(), "application/octet-stream");
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            inputstream.close();
            file.delete();

        }
    }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值