master
huanghai 5 years ago
parent ff28eacd36
commit c7cea80e0e

@ -5,8 +5,6 @@ import (
"dsSupport/Utils/ObsUtil"
"github.com/gin-gonic/gin"
"net/http"
"path"
"strings"
)
//模块的路由配置
@ -17,19 +15,14 @@ func Routers(r *gin.RouterGroup) {
return
}
// http://127.0.0.1:9000/surpport/preview/preview
// http://127.0.0.1:9000/support/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
}
p :=c.Query("p")
fullPath:="C:\\Users\\Administrator\\Desktop\\技术讨论会\\"+p
//判断是不是本地存在
isExist, err := CommonUtil.PathExists(p)
isExist, err := CommonUtil.PathExists(fullPath)
if err != nil {
c.String(http.StatusOK, "发生严重错误:"+err.Error())
return
@ -39,11 +32,10 @@ func preview(c *gin.Context) {
return
}
//将文件上传到华为云
key := "dsMinPreview/" + filenameOnly
ObsUtil.UploadFileMultiPart(key, p)
key := "dsMinPreview/" + p
ObsUtil.UploadFileMultiPart(key, fullPath)
//返回地址
// 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
url := "http://ow365.cn/?i=14531&fname=" + p + "&furl=http%3A%2F%2Fvideo.edusoa.com%2F" + key
//输出预览地址
c.String(http.StatusOK, url)
}

@ -0,0 +1,22 @@
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
p := "20A4782A-512C-40ED-8AF9-FCFC7CD29E5B.docx"
turl := "http://127.0.0.1:9000/support/preview/preview"
resp, err := http.Get(turl+"?p="+p)
if err != nil {
// handle error
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
// handle error
}
fmt.Println(string(body))
}
Loading…
Cancel
Save