Compare commits
No commits in common. "d33597766a56f123b5c571ed9d1cb6a75b096c6a" and "c943ced9f6036bd42599fc3a77496294a51a5460" have entirely different histories.
d33597766a
...
c943ced9f6
|
|
@ -1,11 +1,8 @@
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"videoplayer/dao"
|
"videoplayer/dao"
|
||||||
"videoplayer/proto"
|
"videoplayer/proto"
|
||||||
|
|
@ -78,32 +75,13 @@ func DownloadFile(c *gin.Context) {
|
||||||
id, _ := c.Get("id")
|
id, _ := c.Get("id")
|
||||||
//查询文件信息
|
//查询文件信息
|
||||||
//file := dao.FindFileByNames(file_id, int(id.(float64)))
|
//file := dao.FindFileByNames(file_id, int(id.(float64)))
|
||||||
file_ := dao.FindFileByID(file_id, int(id.(float64)))
|
file := dao.FindFileByID(file_id, int(id.(float64)))
|
||||||
if file_.ID == 0 {
|
if file.ID == 0 {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "file not found", "code": proto.FileNotFound, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": "file not found", "code": proto.FileNotFound, "message": "failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//下载文件
|
//下载文件
|
||||||
// 打开文件
|
c.File(file.FilePath + file.FileStoreName)
|
||||||
file, err := os.Open(file_.FilePath + "/" + file_.FileStoreName)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Internal Server Error", "message": "Failed to open file"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
// 设置响应头
|
|
||||||
c.Writer.Header().Set("Content-Type", "application/octet-stream")
|
|
||||||
c.Writer.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", file_.FileName))
|
|
||||||
|
|
||||||
// 发送文件内容
|
|
||||||
_, err = io.Copy(c.Writer, file)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Internal Server Error", "message": "Failed to send file"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Status(http.StatusOK)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetRedis(c *gin.Context) {
|
func SetRedis(c *gin.Context) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue