| | |
| | | } |
| | | return null; |
| | | } |
| | | /** |
| | | * 文件上传 |
| | | * |
| | | * @param file 要上传的文件 |
| | | * @return |
| | | */ |
| | | public String uploadRetFileName(MultipartFile file, String name) { |
| | | if (null != file) { |
| | | try { |
| | | UUID uuid = UUID.randomUUID(); |
| | | StringBuilder s = new StringBuilder(); |
| | | s.append(uuid.toString().replace("-", "")).append("/"); |
| | | MinioClient minioClient = new MinioClient(minioProperties.getHost(), minioProperties.getAccessKey(), |
| | | minioProperties.getSecretKey()); |
| | | // bucket 不存在,创建 |
| | | if (!minioClient.bucketExists(minioProperties.getBucket())) { |
| | | minioClient.makeBucket(minioProperties.getBucket()); |
| | | } |
| | | // 得到文件流 |
| | | InputStream input = file.getInputStream(); |
| | | // 文件名 |
| | | // String fileName = uuid + "/images." + FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String fileName = s.append(name).toString(); |
| | | String contentType = file.getContentType(); |
| | | minioClient.putObject(minioProperties.getBucket(), fileName, input, contentType); |
| | | StringBuilder fileUrl = new StringBuilder(minioProperties.getUrl()); |
| | | String url = fileUrl.append(fileName).toString(); |
| | | return fileName; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 文件上传 |