Showing
4 changed files
with
30 additions
and
0 deletions
... | ... | @@ -3,6 +3,9 @@ package org.thingsboard.server.controller.yunteng; |
3 | 3 | import org.springframework.http.ResponseEntity; |
4 | 4 | import org.springframework.web.bind.annotation.*; |
5 | 5 | import org.springframework.web.multipart.MultipartFile; |
6 | +import org.thingsboard.server.common.data.StringUtils; | |
7 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | |
8 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
6 | 9 | import org.thingsboard.server.common.data.yunteng.core.utils.FileStorageService; |
7 | 10 | import org.thingsboard.server.common.data.yunteng.dto.FileUploadResponse; |
8 | 11 | |
... | ... | @@ -29,4 +32,11 @@ public class TkOssFileController { |
29 | 32 | @PathVariable String fileName, HttpServletRequest request, HttpServletResponse response) { |
30 | 33 | return fileStorageService.download(fileName, request, response); |
31 | 34 | } |
35 | + @DeleteMapping | |
36 | + public ResponseEntity<Boolean> deleteFile(@RequestParam("deleteFilePath") String deleteFilePath){ | |
37 | + if(StringUtils.isEmpty(deleteFilePath)){ | |
38 | + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
39 | + } | |
40 | + return ResponseEntity.ok(fileStorageService.deleteFile(deleteFilePath)); | |
41 | + } | |
32 | 42 | } | ... | ... |
... | ... | @@ -28,4 +28,6 @@ public interface FileStorageService { |
28 | 28 | String fileName, HttpServletRequest request, HttpServletResponse response); |
29 | 29 | |
30 | 30 | String uploadFile(String fileName, String contentType, InputStream inputStream) throws Exception; |
31 | + | |
32 | + boolean deleteFile(String deleteFilePath); | |
31 | 33 | } | ... | ... |
... | ... | @@ -131,6 +131,11 @@ public class LocalFileStorageService implements FileStorageService { |
131 | 131 | return ossStaticPath; |
132 | 132 | } |
133 | 133 | |
134 | + @Override | |
135 | + public boolean deleteFile(String deleteFilePath) { | |
136 | + return false; | |
137 | + } | |
138 | + | |
134 | 139 | private String storeFileByInputStream(String fileName, InputStream inputStream) |
135 | 140 | throws IOException { |
136 | 141 | // random fileName if needed | ... | ... |
... | ... | @@ -173,6 +173,19 @@ public class MinioFileStorageService implements FileStorageService { |
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
176 | + @Override | |
177 | + public boolean deleteFile(String deleteFilePath) { | |
178 | + boolean result =false; | |
179 | + try{ | |
180 | + minioClient.removeObject(RemoveObjectArgs.builder().bucket(fileStorageProperties.getBucketName()) | |
181 | + .object(deleteFilePath).build()); | |
182 | + result = true; | |
183 | + }catch (Exception e){ | |
184 | + log.error("文件删除失败:{}",deleteFilePath); | |
185 | + } | |
186 | + return result; | |
187 | + } | |
188 | + | |
176 | 189 | private void checkBucket() |
177 | 190 | throws ServerException, InsufficientDataException, ErrorResponseException, IOException, |
178 | 191 | NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, | ... | ... |