音频上传功能接口
正在显示
4 个修改的文件
包含
62 行增加
和
9 行删除
... | @@ -13,9 +13,18 @@ import io.swagger.annotations.Api; | ... | @@ -13,9 +13,18 @@ import io.swagger.annotations.Api; |
13 | import io.swagger.annotations.ApiOperation; | 13 | import io.swagger.annotations.ApiOperation; |
14 | import lombok.extern.slf4j.Slf4j; | 14 | import lombok.extern.slf4j.Slf4j; |
15 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
16 | import org.springframework.beans.factory.annotation.Value; | ||
16 | import org.springframework.web.bind.annotation.*; | 17 | import org.springframework.web.bind.annotation.*; |
18 | import org.springframework.web.multipart.MultipartException; | ||
19 | import org.springframework.web.multipart.MultipartFile; | ||
20 | import org.springframework.web.multipart.MultipartHttpServletRequest; | ||
21 | import org.springframework.web.multipart.commons.CommonsMultipartResolver; | ||
17 | 22 | ||
18 | import java.util.List; | 23 | import javax.servlet.http.HttpServletRequest; |
24 | import java.io.File; | ||
25 | import java.io.IOException; | ||
26 | import java.sql.Timestamp; | ||
27 | import java.util.*; | ||
19 | 28 | ||
20 | /** | 29 | /** |
21 | * 孪生体管理 | 30 | * 孪生体管理 |
... | @@ -26,6 +35,8 @@ import java.util.List; | ... | @@ -26,6 +35,8 @@ import java.util.List; |
26 | @RequestMapping("/3d/twin") | 35 | @RequestMapping("/3d/twin") |
27 | public class FmTwinController { | 36 | public class FmTwinController { |
28 | 37 | ||
38 | @Value(value = "${skua.path.chunk}") | ||
39 | private String voicePath; | ||
29 | @Autowired | 40 | @Autowired |
30 | private IFmTwinService fmTwinService; | 41 | private IFmTwinService fmTwinService; |
31 | 42 | ||
... | @@ -141,4 +152,46 @@ public class FmTwinController { | ... | @@ -141,4 +152,46 @@ public class FmTwinController { |
141 | return result; | 152 | return result; |
142 | } | 153 | } |
143 | 154 | ||
155 | @AutoLog(value = "上传设备音频文件") | ||
156 | @ApiOperation(value="上传设备音频文件", notes="上传设备音频文件") | ||
157 | @PostMapping("/uploadVoice") | ||
158 | public Result<String> uploadVoice(MultipartFile file, HttpServletRequest req){ | ||
159 | Result<String> result = new Result<String>(); | ||
160 | //获取文件的名字 | ||
161 | String originName = file.getOriginalFilename(); | ||
162 | //判断文件类型 | ||
163 | if(!originName.endsWith(".mp3")) { | ||
164 | result.error500("文件类型不对"); | ||
165 | return result; | ||
166 | } | ||
167 | //若目录不存在则创建目录 | ||
168 | File folder = new File(voicePath); | ||
169 | if(! folder.exists()) { | ||
170 | folder.mkdirs(); | ||
171 | } | ||
172 | //给上传文件取新的名字 | ||
173 | Timestamp timestamp = new Timestamp(System.currentTimeMillis()); | ||
174 | String newName = "voice" + timestamp.getTime() + ".mp3"; | ||
175 | try { | ||
176 | //生成文件,folder为文件目录,newName为文件名 | ||
177 | file.transferTo(new File(folder,newName)); | ||
178 | //生成返回给前端的url | ||
179 | String downStr = File.separator+"fmboot"+File.separator+ | ||
180 | "sys"+File.separator+"common"+File.separator+"download"+File.separator+ | ||
181 | "skboot"+File.separator+"zujianhua"+File.separator+"voice"+File.separator; | ||
182 | if (downStr.contains("\\")) { | ||
183 | downStr = downStr.replace("\\", "/"); | ||
184 | } | ||
185 | String url = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + downStr + newName; | ||
186 | //http://localhost:8803/fmboot/sys/common/download/skboot/zujianhua/voice1671601022510.mp3 | ||
187 | //返回URL | ||
188 | result.setResult(url); | ||
189 | result.setSuccess(true); | ||
190 | }catch (IOException e) { | ||
191 | result.error500("音频上传失败!"); | ||
192 | } | ||
193 | return result; | ||
194 | |||
195 | } | ||
196 | |||
144 | } | 197 | } | ... | ... |
... | @@ -92,15 +92,15 @@ spring: | ... | @@ -92,15 +92,15 @@ spring: |
92 | connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 | 92 | connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 |
93 | datasource: | 93 | datasource: |
94 | master: | 94 | master: |
95 | url: jdbc:mysql://127.0.0.1:13306/zhsw_modules?characterEncoding=UTF-8&useUnicode=true&useSSL=false | 95 | url: jdbc:mysql://115.28.25.233:6630/zhsw_modules?characterEncoding=UTF-8&useUnicode=true&useSSL=false |
96 | username: root | 96 | username: jk_test |
97 | password: bkyh925. | 97 | password: Jk_test1211rw |
98 | driver-class-name: com.mysql.jdbc.Driver | 98 | driver-class-name: com.mysql.jdbc.Driver |
99 | # 多数据源配置 | 99 | # 多数据源配置 |
100 | pg-db: | 100 | pg-db: |
101 | url: jdbc:postgresql://192.168.10.200:10086/postgres?useUnicode=true&characterEncoding=UTF8 | 101 | url: jdbc:postgresql://120.24.205.69:10086/postgres?useUnicode=true&characterEncoding=UTF8 |
102 | username: postgres | 102 | username: postgres |
103 | password: bkyh925. | 103 | password: server_2021_%Jksc |
104 | driver-class-name: org.postgresql.Driver | 104 | driver-class-name: org.postgresql.Driver |
105 | #redis 配置 | 105 | #redis 配置 |
106 | redis: | 106 | redis: |
... | @@ -139,7 +139,7 @@ skua : | ... | @@ -139,7 +139,7 @@ skua : |
139 | #webapp文件路径 | 139 | #webapp文件路径 |
140 | webapp: /mnt/app/uploadfile | 140 | webapp: /mnt/app/uploadfile |
141 | # 断点续传路径 | 141 | # 断点续传路径 |
142 | chunk: /app/fmboot/zjh | 142 | chunk: /app/skboot/zujianhua/voice |
143 | #短信秘钥 | 143 | #短信秘钥 |
144 | sms: | 144 | sms: |
145 | #应用地址 | 145 | #应用地址 | ... | ... |
-
请 注册 或 登录 后发表评论