16 Star 370 Fork 91

tqz / 音乐网站播放器

 / 详情

添加歌曲和更新歌曲问题

待办的
创建于  
2023-05-25 09:34

添加歌曲选择文件无效

更新歌曲的updateSongUrl接口404,服务端代码里面没有这个,请问作者是什么原因啊

manager.SongPage.vue中这段代码,在服务端代码中的接口找不到
//更新歌曲url
uploadSongUrl(id){
return ${this.$store.state.HOST}/song/updateSongUrl?id=${id}
}

评论 (1)

预谋 创建了任务

在server中参照updateSongPic,添加一个updateSongUrlcontroller,pic是上传图片,url是上传歌曲文件,修改对应的文件存储路径和url拼接就可以了
/**
* 更新歌曲路径
*/
@RequestMapping(value = "/updateSongUrl", method = RequestMethod.POST)
public Object updateSongUrl(@RequestParam("file") MultipartFile songFile, @RequestParam("id") int id) {
JSONObject jsonObject = new JSONObject();
//如果文件是空的,直接返回
if (songFile.isEmpty()) {
jsonObject.put(Consts.CODE, 0);
jsonObject.put(Consts.MSG, "文件上传失败");
return jsonObject;
}
//文件名=当前时间到毫秒+原来的文件名
String fileName = songFile.getOriginalFilename();
//文件路径
String filePath = System.getProperty("user.dir") + System.getProperty("file.separator") + "song";
//如果文件路径不存在,新增该路径
File file1 = new File(filePath);
if (!file1.exists()) {
file1.mkdir();
}
//实际的文件地址
File dest = new File(filePath + System.getProperty("file.separator") + fileName);
//存储到数据库里的相对文件地址
String songPath = "/song/" + fileName;
try {
songFile.transferTo(dest);//上传
Song song = new Song();
song.setId(id);
song.setUrl(songPath);
boolean flag = songService.updateById(song);
if (flag) {
jsonObject.put(Consts.CODE, 1);
jsonObject.put(Consts.MSG, "上传成功");
jsonObject.put("url", songPath);
return jsonObject;
}
jsonObject.put(Consts.CODE, 0);
jsonObject.put(Consts.MSG, "上传失败");
return jsonObject;
} catch (IOException e) {
jsonObject.put(Consts.CODE, 0);
jsonObject.put(Consts.MSG, "上传失败" + e.getMessage());
} finally {
return jsonObject;
}
}

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(1)
9141516 premeditate 1644828995
Java
1
https://gitee.com/tqz521127/music-website-player.git
git@gitee.com:tqz521127/music-website-player.git
tqz521127
music-website-player
音乐网站播放器

搜索帮助

344bd9b3 5694891 D2dac590 5694891