Merge branch 'master' of 10.10.14.250:huanghai/dsMin

master
wubin 5 years ago
commit 0b59d99a77

@ -273,7 +273,8 @@ func (s *Rpc) UpdateBaseTeacher(ctx context.Context, in *BaseTeacherProto.ModelA
model.Xwm = in.Xwm
model.Zcm = in.Zcm
model.Bzlbm = in.Bzlbm
//排序号
model.SortId=in.SortId
if len(in.Cjny) == 0 {
model.Cjny = DateUtil.ConvertDate("1900-01-01")
} else {

@ -3,10 +3,12 @@ package PreviewController
import (
"dsSupport/Utils/CommonUtil"
"dsSupport/Utils/ObsUtil"
"encoding/base64"
"fmt"
"github.com/gin-gonic/gin"
"log"
"net/http"
"path"
"strings"
"path/filepath"
)
//模块的路由配置
@ -17,19 +19,26 @@ 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
}
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)
//TODO
//(1)保允许上传office系列的文件
//(2)在上传前判断文件是否已存在,存在了直接返回,不做重复工作,也可以支持强制刷新,需要添加参数
//(3)需要判断文件名是不是是标准的GUID形式不是的不让上传
//(4)对于异常的明显提示信息
//判断是不是本地存在
isExist, err := CommonUtil.PathExists(p)
isExist, err := CommonUtil.PathExists(fullPath)
if err != nil {
c.String(http.StatusOK, "发生严重错误:"+err.Error())
return
@ -39,11 +48,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,24 @@
package main
import (
"encoding/base64"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
// 如果要用在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, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
//Java的调用方法示例
//https://blog.csdn.net/orangleliu/article/details/38309367
}
Loading…
Cancel
Save