You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package PreviewController
import (
"dsSupport/Utils/CommonUtil"
"dsSupport/Utils/ObsUtil"
"github.com/gin-gonic/gin"
"net/http"
"path"
"strings"
)
//模块的路由配置
func Routers ( r * gin . RouterGroup ) {
rr := r . Group ( "/preview" )
//配置接口
rr . GET ( "/preview" , preview )
return
}
// http://127.0.0.1:9000/surpport/preview/preview
func preview ( c * gin . Context ) {
//本地物理路径
p := c . Query ( "p" )
filenameWithSuffix := path . Base ( p ) //获取文件名带后缀
fileSuffix := path . Ext ( filenameWithSuffix ) //获取文件后缀
filenameOnly := strings . TrimSuffix ( filenameWithSuffix , fileSuffix ) //获取文件名
if len ( filenameOnly ) != 36 {
c . String ( http . StatusOK , "输入的文件名只支持GUID格式! " )
return
}
//判断是不是本地存在
isExist , err := CommonUtil . PathExists ( p )
if err != nil {
c . String ( http . StatusOK , "发生严重错误:" + err . Error ( ) )
return
}
if ! isExist {
c . String ( http . StatusOK , "输入的文件无法找到!" )
return
}
//将文件上传到华为云
key := "dsMinPreview/" + filenameOnly
ObsUtil . UploadFileMultiPart ( key , p )
//返回地址
// http://ow365.cn/?i=14531&fname=6F8D046F-6D0E-CEE3-A2DE-661EA77DCABB&furl=http%3A%2F%2Fvideo.edusoa.com%2Fdown%2FMaterial%2F6F%2F6F8D046F-6D0E-CEE3-A2DE-661EA77DCABB.docx
url := "http://ow365.cn/?i=14531&fname=" + filenameOnly + "&furl=http%3A%2F%2Fvideo.edusoa.com%2F" + key
//输出预览地址
c . String ( http . StatusOK , url )
}