summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/web.go12
-rw-r--r--routers/repo/download.go20
2 files changed, 23 insertions, 9 deletions
diff --git a/cmd/web.go b/cmd/web.go
index decad7d34f..6ca771e230 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -338,9 +338,19 @@ func runWeb(ctx *cli.Context) {
return
}
+ fr, err := os.Open(attach.LocalPath())
+ if err != nil {
+ ctx.Handle(500, "Open", err)
+ return
+ }
+ defer fr.Close()
+
// Fix #312. Attachments with , in their name are not handled correctly by Google Chrome.
// We must put the name in " manually.
- ctx.ServeFileContent(attach.LocalPath(), "\""+attach.Name+"\"")
+ if err = repo.ServeData(ctx, "\""+attach.Name+"\"", fr); err != nil {
+ ctx.Handle(500, "ServeData", err)
+ return
+ }
})
m.Post("/issues/attachments", repo.UploadIssueAttachment)
}, ignSignIn)
diff --git a/routers/repo/download.go b/routers/repo/download.go
index c71f8d293e..a0a7823b52 100644
--- a/routers/repo/download.go
+++ b/routers/repo/download.go
@@ -13,14 +13,9 @@ import (
"github.com/gogits/gogs/modules/middleware"
)
-func ServeBlob(ctx *middleware.Context, blob *git.Blob) error {
- dataRc, err := blob.Data()
- if err != nil {
- return err
- }
-
+func ServeData(ctx *middleware.Context, name string, reader io.Reader) error {
buf := make([]byte, 1024)
- n, _ := dataRc.Read(buf)
+ n, _ := reader.Read(buf)
if n > 0 {
buf = buf[:n]
}
@@ -39,10 +34,19 @@ func ServeBlob(ctx *middleware.Context, blob *git.Blob) error {
}
}
ctx.Resp.Write(buf)
- _, err = io.Copy(ctx.Resp, dataRc)
+ _, err := io.Copy(ctx.Resp, reader)
return err
}
+func ServeBlob(ctx *middleware.Context, blob *git.Blob) error {
+ dataRc, err := blob.Data()
+ if err != nil {
+ return err
+ }
+
+ return ServeData(ctx, ctx.Repo.TreeName, dataRc)
+}
+
func SingleDownload(ctx *middleware.Context) {
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName)
if err != nil {