diff --git a/dsSupport/Business/Preview/PreviewController/PreviewController.go b/dsSupport/Business/Preview/PreviewController/PreviewController.go index 4220abbc..dc0e7089 100644 --- a/dsSupport/Business/Preview/PreviewController/PreviewController.go +++ b/dsSupport/Business/Preview/PreviewController/PreviewController.go @@ -3,8 +3,12 @@ package PreviewController import ( "dsSupport/Utils/CommonUtil" "dsSupport/Utils/ObsUtil" + "encoding/base64" + "fmt" "github.com/gin-gonic/gin" + "log" "net/http" + "path/filepath" ) //模块的路由配置 @@ -18,9 +22,15 @@ func Routers(r *gin.RouterGroup) { // http://127.0.0.1:9000/support/preview/preview func preview(c *gin.Context) { //本地物理路径 - p :=c.Query("p") + uEnc :=c.Query("p") + uDec, err := base64.URLEncoding.DecodeString(uEnc) + if err != nil { + log.Fatalln(err) + } + fullPath:=string(uDec) + fmt.Println(fullPath) + _, p := filepath.Split(fullPath) - fullPath:="C:\\Users\\Administrator\\Desktop\\技术讨论会\\"+p //判断是不是本地存在 isExist, err := CommonUtil.PathExists(fullPath) if err != nil { diff --git a/dsSupport/Test/PreviewTest/PreviewTest.go b/dsSupport/Test/PreviewTest/PreviewTest.go index 2c4dc332..925628bc 100644 --- a/dsSupport/Test/PreviewTest/PreviewTest.go +++ b/dsSupport/Test/PreviewTest/PreviewTest.go @@ -1,22 +1,21 @@ package main import ( + "encoding/base64" "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 - } + // 如果要用在url中,需要使用URLEncoding + input:="C:\\Users\\Administrator\\Desktop\\技术讨论会\\20A4782A-512C-40ED-8AF9-FCFC7CD29E5B.docx" + uEnc := base64.URLEncoding.EncodeToString([]byte(input)) + fmt.Println(uEnc) + //生成预览OFFICE的服务地址 + url := "http://10.10.24.100:9000/support/preview/preview" + resp, _ := http.Get(url+"?p="+uEnc) defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - // handle error - } + body, _ := ioutil.ReadAll(resp.Body) fmt.Println(string(body)) }