-
Notifications
You must be signed in to change notification settings - Fork 1
/
transcode.go
45 lines (36 loc) · 1.01 KB
/
transcode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"io"
"net/http"
"os"
)
func websrvTranscodeForm(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
file, err := os.Open("demo.html")
if err != nil {
panic(err)
}
defer file.Close()
io.Copy(w, file)
}
func websrvTranscode(w http.ResponseWriter, r *http.Request) {
// Parse our multipart form, 10 << 20 specifies a maximum
// upload of 10 MB files.
r.ParseMultipartForm(100 << 20)
// FormFile returns the first file for the given key `myFile`
// it also returns the FileHeader so we can get the Filename,
// the Header and the size of the file
file, _, err := r.FormFile("source")
if err != nil {
panic(err)
}
defer file.Close()
websrvTranscodeResponse(w, r, file)
}
func websrvTranscodeResponse(w http.ResponseWriter, r *http.Request, file io.ReadCloser) {
w.Header().Set("Content-Type", "audio/mpeg")
w.Header().Set("Accept-Ranges", "none")
w.WriteHeader(http.StatusOK)
transcode_audio(w, file)
}