package main import ( "fmt" "io" "net/http" "os/exec" "strings" ) func uploadHandler(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodPost { err := r.ParseMultipartForm(15 * 1024 * 1024 * 1024) // limit 15 gb if err != nil { http.Error(w, "Unable to parse form", http.StatusBadRequest) return } file, _, err := r.FormFile("file") if err != nil { http.Error(w, "Unable to retrieve file", http.StatusBadRequest) return } defer file.Close() // Upload the file req, err := http.NewRequest("POST", "http://localhost:3880", file) if err != nil { http.Error(w, "Error creating request", http.StatusInternalServerError) return } client := &http.Client{} resp, err := client.Do(req) if err != nil { http.Error(w, "Error uploading to transfer.sh", http.StatusInternalServerError) return } defer resp.Body.Close() // Unique ID to track file for ffmpeg etc responseURL, err := io.ReadAll(resp.Body) if err != nil { http.Error(w, "Error reading response", http.StatusInternalServerError) return } urlParts := strings.Split(string(responseURL), "/") uniqueID := urlParts[len(urlParts)-1] // Convert file to HLS. Work on error catching and flags tomorrow // IF VIDEO=DO THIS. IF NOT CONTINUE! // ALSO CHANGE THE CODE. IF VIDEO, REDIRECT TO S3 BUCKET // CURRENTLY FILE IS STANDARD UPLOAD TO SERVER cmd := exec.Command("ffmpeg") // HTML w.Header().Set("Content-Type", "text/html") fmt.Fprint(w, `
Unique ID: %s
Upload Another `, uniqueID, string(responseURL), string(responseURL)) return } // Original GET form w.Header().Set("Content-Type", "text/html") fmt.Fprint(w, `Make sure to copy the link in the next page!
More info on third culture upload here.