Permalink
Browse files

Server a file from memory.

  • Loading branch information...
1 parent 9f5aba1 commit 278b71acf6f019a9cdd3c99e00307f6490a4cad1 @jcvernaleo jcvernaleo committed Jul 31, 2013
Showing with 17 additions and 0 deletions.
  1. +17 −0 controller.go
View
@@ -3,6 +3,7 @@ package revel
import (
"errors"
"fmt"
+ "io"
"net/http"
"os"
"path/filepath"
@@ -187,6 +188,22 @@ func (c *Controller) RenderFile(file *os.File, delivery ContentDisposition) Resu
}
}
+// renderMemory is like RenderFile() expect that it renders a file that is kept
+// in memory rather than an ondisk os.File so content can be delivered
+// dynamically.
+func (c *Controller) RenderMemory(memfile io.Reader, filename string, delivery ContentDisposition) Result {
+ var (
+ modtime = time.Now()
+ )
+ return &BinaryResult{
+ Reader: memfile,
+ Name: filename,
+ Delivery: delivery,
+ Length: -1, // http.ServeContent gets the length itself
+ ModTime: modtime,
+ }
+}
+
// Redirect to an action or to a URL.
// c.Redirect(Controller.Action)
// c.Redirect("/controller/action")

0 comments on commit 278b71a

Please sign in to comment.