Fix: upload was marked canceled when small file uploaded

This commit is contained in:
HFO4
2019-11-27 12:49:31 +08:00
parent 4156a71adf
commit 29def02489
8 changed files with 71 additions and 21 deletions

View File

@@ -5,6 +5,8 @@ import (
"github.com/HFO4/cloudreve/pkg/filesystem"
"github.com/HFO4/cloudreve/pkg/serializer"
"github.com/gin-gonic/gin"
"net/http"
"time"
)
// FileDownloadService 文件下载服务path为文件完整路径
@@ -22,12 +24,16 @@ func (service *FileDownloadService) Download(ctx context.Context, c *gin.Context
// 开始处理下载
ctx = context.WithValue(ctx, filesystem.GinCtx, c)
_, err = fs.Download(ctx, service.Path)
rs, err := fs.GetContent(ctx, service.Path)
if err != nil {
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
}
// 设置文件名
c.Header("Content-Disposition", "attachment; filename=\""+fs.Target.Name+"\"")
// 发送文件
http.ServeContent(c.Writer, c.Request, "", time.Time{}, rs)
return serializer.Response{
Code: 0,
}