| | |
| | | import org.springblade.modules.resource.builder.oss.OssBuilder; |
| | | import org.springblade.modules.resource.entity.Attach; |
| | | import org.springblade.modules.resource.service.IAttachService; |
| | | import org.springblade.modules.system.entity.User; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import sun.misc.BASE64Decoder; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.security.InvalidKeyException; |
| | |
| | | return R.data(bladeFile); |
| | | } |
| | | |
| | | /** |
| | | * base64 图片上传 |
| | | * @param base64 字符串 |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public String uploadBase64String(String base64) throws Exception { |
| | | String[] split = base64.split(","); |
| | | //图片上传 |
| | | BASE64Decoder decoder = new BASE64Decoder(); |
| | | // 解密 |
| | | byte[] b = decoder.decodeBuffer(split[1]); |
| | | // 处理数据 |
| | | // for (int i = 0; i < b.length; ++i) { |
| | | // if (b[i] < 0) { |
| | | // b[i] += 256; |
| | | // } |
| | | // } |
| | | //填写你文件上传的地址以及相应信息 |
| | | String url = "http://61.131.136.25:2081"; |
| | | String access = "zhbaadmin"; |
| | | String secret = "zhbapassword"; |
| | | String bucket = "zhba"; |
| | | MinioClient minioClient = |
| | | MinioClient.builder() |
| | | .endpoint(url) |
| | | .credentials(access, secret) |
| | | .build(); |
| | | // 检查存储桶是否已经存在 |
| | | boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket).build()); |
| | | if (!isExist) { |
| | | // 创建一个名为zip的存储桶,用于zip文件。 |
| | | minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build()); |
| | | minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).build()); |
| | | } |
| | | String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "") + ".jpg"; |
| | | InputStream in = new ByteArrayInputStream(b); |
| | | //创建头部信息 |
| | | Map<String, String> headers = new HashMap<>(1 << 2); |
| | | //添加自定义内容类型 |
| | | headers.put("Content-Type", "application/octet-stream"); |
| | | //上传 |
| | | minioClient.putObject( |
| | | PutObjectArgs.builder().bucket(bucket).object(newName).stream( |
| | | in, in.available(), -1) |
| | | .headers(headers) |
| | | .build()); |
| | | in.close(); |
| | | //url |
| | | String urls = "http://61.131.136.25:2081/zhba/" + newName; |
| | | //返回 |
| | | return urls; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 文件上传,自定义上传 |