StorageController.java
1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.glsx.usedcar.controller;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.summerframework.storage.FileStorageException;
import org.summerframework.storage.domain.FileInfo;
import org.summerframework.storage.web.AbstractStorageController;
import java.util.*;
/**
* @author kepler
*/
@Slf4j
@RestController
@RequestMapping("/rest/upload")
public class StorageController extends AbstractStorageController {
public static final String[] AUDIO_SUFFIXES = new String[]{"wav", "mp3", "aac", "m4a", "flac", "amr", "ogg", "opus"};
@PostMapping({"uploadAudio"})
protected FileInfo uploadAudio(@RequestParam MultipartFile file, @RequestParam String directory) throws FileStorageException {
return this.storageService.createFile(file, directory, AUDIO_SUFFIXES);
}
@Override
protected String[] getDefaultFileSuffixes() {
return null;
}
/**
* 富文本图片上传
*
* @param file
* @param request
* @return
* @throws FileStorageException
*/
@PostMapping(value = "uploadRichTextImage")
public Map<String, Object> uploadPasteImage(@RequestParam("upload") MultipartFile file, HttpServletRequest request) throws FileStorageException {
FileInfo fileBean = storageService.createFile(file, "richtext", true, "jpg,png,jpeg,pdf,doc,docx,xls,xlsx,zip,blob,mp4,avi,wmv,3gp,flv,out,txt".split(","));
Map<String, Object> map = new HashMap<>();
if (Objects.nonNull(fileBean)) {
map.put("uploaded", 1);
map.put("fileName", fileBean.getName());
map.put("url", fileBean.getUrl());
} else {
map.put("uploaded", 1);
map.put("fileName", "image");
map.put("url", "image");
map.put("error", "{message: \"图片上传失败\"}");
}
return map;
}
}