+func handleDownload(w http.ResponseWriter, r *http.Request) {
+ path := r.URL.Path[1:]
+ tok := strings.Split(path, "/")
+ if 2 != len(tok) {
+ fmt.Fprintln(w, "Unexpected path for download:", path)
+ return
+ }
+ efsId, err := strconv.Atoi(tok[1])
+ if (nil != err) || (0 == efsId) {
+ fmt.Fprintln(w, "Invalid id for download:", path, err)
+ return
+ }
+
+ mimeType := queryMimeTypeByEfsId(efsId)
+ if 0 == len(mimeType) {
+ fmt.Fprintln(w, "No MIME type found for id:", efsId)
+ return
+ }
+
+ efsPath := efsPathForId(efsId)
+
+ var fd *os.File
+ fd, err = os.Open(efsPath)
+ if nil != err {
+ fmt.Fprintln(w, "Failed to read file for id:", efsId, err)
+ return
+ }
+ defer fd.Close()
+
+ io.Copy(w, fd)
+}
+