| | |
| | | @PostMapping("put-files-talk") |
| | | public String putFilestak(@RequestParam MultipartFile file) throws IOException, ServerException, InsufficientDataException, InternalException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, XmlParserException, ErrorResponseException { |
| | | //填写你文件上传的地址以及相应信息 |
| | | String url = "http://223.82.109.183:2081"; |
| | | String access = "zhbaadmin"; |
| | | String secret = "zhbapassword"; |
| | | String bucket = "zhxy"; |
| | | String url = "http://web.byisf.com:9000"; |
| | | String access = "adminminio"; |
| | | String secret = "adminminio"; |
| | | String bucket = "jfpt"; |
| | | MinioClient minioClient = |
| | | MinioClient.builder() |
| | | .endpoint(url) |
| | |
| | | .build()); |
| | | |
| | | //文件推送 |
| | | String urls = "http://223.82.109.183:2081/zhxy/"+newName; |
| | | String urls = "http://web.byisf.com:9000/jfpt/"+newName; |
| | | //返回 |
| | | return urls; |
| | | } |
| | | |
| | | /** |
| | | * 文件上传,个人头像上传 |
| | | * |
| | | * @param file 图片对象 |
| | | */ |
| | | @GetMapping("put-files-talks") |
| | | public String putFilestaks(@RequestParam MultipartFile file) throws IOException, ServerException, InsufficientDataException, InternalException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, XmlParserException, ErrorResponseException { |
| | | //填写你文件上传的地址以及相应信息 |
| | | String url = "http://web.byisf.com:9000"; |
| | | String access = "adminminio"; |
| | | String secret = "adminminio"; |
| | | String bucket = "jfpt"; |
| | | 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 fileName = file.getOriginalFilename(); |
| | | String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "") |
| | | + fileName.substring(fileName.lastIndexOf(".")); |
| | | InputStream in = file.getInputStream(); |
| | | String[] split = newName.split("/"); |
| | | //创建头部信息 |
| | | 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()); |
| | | |
| | | //文件推送 |
| | | String urls = "http://web.byisf.com:9000/jfpt/"+newName; |
| | | //返回 |
| | | return urls; |
| | | } |