ea4423ab 张雷

音频上传功能接口

1 个父辈 dac513da
......@@ -13,9 +13,18 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.*;
/**
* 孪生体管理
......@@ -26,6 +35,8 @@ import java.util.List;
@RequestMapping("/3d/twin")
public class FmTwinController {
@Value(value = "${skua.path.chunk}")
private String voicePath;
@Autowired
private IFmTwinService fmTwinService;
......@@ -141,4 +152,46 @@ public class FmTwinController {
return result;
}
@AutoLog(value = "上传设备音频文件")
@ApiOperation(value="上传设备音频文件", notes="上传设备音频文件")
@PostMapping("/uploadVoice")
public Result<String> uploadVoice(MultipartFile file, HttpServletRequest req){
Result<String> result = new Result<String>();
//获取文件的名字
String originName = file.getOriginalFilename();
//判断文件类型
if(!originName.endsWith(".mp3")) {
result.error500("文件类型不对");
return result;
}
//若目录不存在则创建目录
File folder = new File(voicePath);
if(! folder.exists()) {
folder.mkdirs();
}
//给上传文件取新的名字
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
String newName = "voice" + timestamp.getTime() + ".mp3";
try {
//生成文件,folder为文件目录,newName为文件名
file.transferTo(new File(folder,newName));
//生成返回给前端的url
String downStr = File.separator+"fmboot"+File.separator+
"sys"+File.separator+"common"+File.separator+"download"+File.separator+
"skboot"+File.separator+"zujianhua"+File.separator+"voice"+File.separator;
if (downStr.contains("\\")) {
downStr = downStr.replace("\\", "/");
}
String url = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + downStr + newName;
//http://localhost:8803/fmboot/sys/common/download/skboot/zujianhua/voice1671601022510.mp3
//返回URL
result.setResult(url);
result.setSuccess(true);
}catch (IOException e) {
result.error500("音频上传失败!");
}
return result;
}
}
......
......@@ -139,7 +139,7 @@ skua :
#webapp文件路径
webapp: d:/app
# 断点续传路径
chunk: /app/fmboot/zjh
chunk: d:/app/skboot/zujianhua/voice
#短信秘钥
sms:
#应用地址
......
......@@ -92,15 +92,15 @@ spring:
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
master:
url: jdbc:mysql://127.0.0.1:13306/zhsw_modules?characterEncoding=UTF-8&useUnicode=true&useSSL=false
username: root
password: bkyh925.
url: jdbc:mysql://115.28.25.233:6630/zhsw_modules?characterEncoding=UTF-8&useUnicode=true&useSSL=false
username: jk_test
password: Jk_test1211rw
driver-class-name: com.mysql.jdbc.Driver
# 多数据源配置
pg-db:
url: jdbc:postgresql://192.168.10.200:10086/postgres?useUnicode=true&characterEncoding=UTF8
url: jdbc:postgresql://120.24.205.69:10086/postgres?useUnicode=true&characterEncoding=UTF8
username: postgres
password: bkyh925.
password: server_2021_%Jksc
driver-class-name: org.postgresql.Driver
#redis 配置
redis:
......@@ -139,7 +139,7 @@ skua :
#webapp文件路径
webapp: /mnt/app/uploadfile
# 断点续传路径
chunk: /app/fmboot/zjh
chunk: /app/skboot/zujianhua/voice
#短信秘钥
sms:
#应用地址
......
spring:
profiles:
active: dev
active: prod
# 信息安全
security:
csrf:
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!