package main import ( "fmt" "io/ioutil" "log" "net/http" "os" "path" "path/filepath" ) func uploaderPut(w http.ResponseWriter, r *http.Request) { /* limit upload size */ if r.ContentLength > conf.maxsize { http.Error(w, "File is too big", http.StatusRequestEntityTooLarge) } tmp, _ := ioutil.TempFile(conf.filepath, "*"+path.Ext(r.URL.Path)) f, err := os.Create(tmp.Name()) if err != nil { fmt.Println(err) return } defer f.Close() if verbose { log.Printf("Writing %d bytes to %s", r.ContentLength, tmp.Name()) } if err = writefile(f, r.Body, r.ContentLength); err != nil { http.Error(w, "Internal error", http.StatusInternalServerError) defer os.Remove(tmp.Name()) return } writemeta(tmp.Name(), conf.expiry) resp := conf.baseuri + conf.filectx + filepath.Base(tmp.Name()) w.Write([]byte(resp + "\r\n")) }