r := gin.Default()
//Get路由,动态路由
r.GET("/GetFile/:name", DowFile)
// DowFile 文件在线预览
func DowFile(c *gin.Context){
//通过动态路由方式获取文件名,以实现下载不同文件的功能
name:=c.Param("name")
uploadType := c.Query("type")
fmt.Println(uploadType)
fmt.Println(name)
var uploadT = ""
if uploadType =="1" {
uploadT ="teaching"
}else {
uploadT ="professional"
}
var localPath = "./dataset/"+uploadT+"/"+name
err:=minioTest.DownloadObject(uploadT, name, localPath)
fmt.Println("**************")
fmt.Println(err)
if err =="error"{
c.HTML(http.StatusOK, "error.html", gin.H{
"title": "error",
})
}else{
//拼接路径,如果没有这一步,则默认在当前路径下寻找
//filename:=path.Join("./dataset/professional/",name)
filename:=path.Join("./dataset/"+uploadT+"/",name)
//响应一个文件
c.File(filename)
return
}
}