1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package upload
- import (
- "fmt"
- "kpt-pasture/config"
- "kpt-pasture/http/middleware"
- "net/http"
- "os"
- "gitee.com/xuyiping_admin/pkg/apierr"
- "gitee.com/xuyiping_admin/pkg/xerr"
- "github.com/gin-gonic/gin"
- )
- func Photos(c *gin.Context) {
- form, err := c.MultipartForm()
- if err != nil {
- apierr.AbortBadRequest(c, http.StatusBadRequest, xerr.Customf("No multipartForm: %s", err.Error()))
- return
- }
- files := form.File["uploads"]
- // 验证文件数量
- if len(files) == 0 {
- apierr.AbortBadRequest(c, http.StatusBadRequest, xerr.Custom("No files selected"))
- return
- }
- res, err := middleware.BackendOperation(c).OpsService.Photos(c, files)
- if err != nil {
- apierr.AbortBadRequest(c, http.StatusBadRequest, err)
- return
- }
- c.JSON(http.StatusOK, gin.H{"code": http.StatusOK, "Msg": "ok", "data": res})
- }
- func Files(c *gin.Context) {
- }
- func OssVideo(c *gin.Context) {
- filename := c.Param("name")
- videoPath := fmt.Sprintf("%s/files/video/%s", config.WorkDir, filename)
- // 打开视频文件
- file, err := os.Open(videoPath)
- if err != nil {
- c.JSON(http.StatusNotFound, gin.H{"error": "Video not found"})
- return
- }
- defer file.Close()
- fileInfo, err := file.Stat()
- if err != nil {
- c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not get file info"})
- return
- }
- // 设置响应头
- c.Header("Content-Type", "video/mp4")
- c.Header("Content-Length", fmt.Sprintf("%d", fileInfo.Size()))
- // 流式传输文件内容
- http.ServeContent(c.Writer, c.Request, fileInfo.Name(), fileInfo.ModTime(), file)
- }
|