From c7cea80e0edd7065ed65cc948123353706b2b33a Mon Sep 17 00:00:00 2001 From: huanghai <10402852@qq.com> Date: Wed, 15 Jul 2020 11:21:36 +0800 Subject: [PATCH] 'commit' --- .../PreviewController/PreviewController.go | 24 +++++++------------ dsSupport/Test/PreviewTest/PreviewTest.go | 22 +++++++++++++++++ 2 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 dsSupport/Test/PreviewTest/PreviewTest.go diff --git a/dsSupport/Business/Preview/PreviewController/PreviewController.go b/dsSupport/Business/Preview/PreviewController/PreviewController.go index 105ea2e4..4220abbc 100644 --- a/dsSupport/Business/Preview/PreviewController/PreviewController.go +++ b/dsSupport/Business/Preview/PreviewController/PreviewController.go @@ -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) } diff --git a/dsSupport/Test/PreviewTest/PreviewTest.go b/dsSupport/Test/PreviewTest/PreviewTest.go new file mode 100644 index 00000000..2c4dc332 --- /dev/null +++ b/dsSupport/Test/PreviewTest/PreviewTest.go @@ -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)) +}