Add the file downloader.
This commit is contained in:
@ -3,12 +3,12 @@ package rest
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type AlienController struct {
|
||||
@ -347,22 +347,21 @@ func (this *AlienController) Download(writer http.ResponseWriter, request *http.
|
||||
this.PanicError(err)
|
||||
defer diskFile.Close()
|
||||
|
||||
// 防止中文乱码
|
||||
fileName := url.QueryEscape(matter.Name)
|
||||
mimeType := GetMimeType(fileName)
|
||||
writer.Header().Set("Content-Type", mimeType)
|
||||
|
||||
//如果是图片或者文本或者视频就直接打开。其余的一律以下载形式返回。
|
||||
if strings.Index(mimeType, "image") != 0 && strings.Index(mimeType, "text") != 0 && strings.Index(mimeType, "video") != 0 {
|
||||
writer.Header().Set("content-disposition", "attachment; filename=\""+fileName+"\"")
|
||||
}
|
||||
|
||||
//对图片做缩放处理。
|
||||
imageProcess := request.FormValue("imageProcess")
|
||||
if imageProcess == "resize" {
|
||||
this.matterService.ResizeImage(writer, request, matter, diskFile)
|
||||
} else {
|
||||
|
||||
//如果是图片或者文本或者视频就直接打开。其余的一律以下载形式返回。
|
||||
fileName := url.QueryEscape(matter.Name)
|
||||
mimeType := GetMimeType(fileName)
|
||||
if strings.Index(mimeType, "image") != 0 && strings.Index(mimeType, "text") != 0 && strings.Index(mimeType, "video") != 0 {
|
||||
writer.Header().Set("content-disposition", "attachment; filename=\""+fileName+"\"")
|
||||
}
|
||||
|
||||
this.matterService.DownloadFile(writer, request, matter, diskFile)
|
||||
|
||||
//显示文件大小。
|
||||
//fileInfo, err := diskFile.Stat()
|
||||
//if err != nil {
|
||||
|
Reference in New Issue
Block a user