fix upload

This commit is contained in:
Henrique Dias 2016-02-07 21:39:34 +00:00
parent 23f191361a
commit ee518d0ec6
1 changed files with 4 additions and 4 deletions

View File

@ -16,12 +16,12 @@ import (
// POST handles the POST method on browse page // POST handles the POST method on browse page
func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) { func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
// Remove both beginning slashes // Remove prefix slash
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/") r.URL.Path = strings.TrimPrefix(r.URL.Path, "/")
// If it's the upload of a file // If it's the upload of a file
if r.Header.Get("X-Upload") == "true" { if r.Header.Get("X-Upload") == "true" {
return upload(w, r) return upload(w, r, c)
} }
// Get the JSON information sent using a buffer // Get the JSON information sent using a buffer
@ -101,7 +101,7 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
return http.StatusOK, nil return http.StatusOK, nil
} }
func upload(w http.ResponseWriter, r *http.Request) (int, error) { func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
// Parse the multipart form in the request // Parse the multipart form in the request
err := r.ParseMultipartForm(100000) err := r.ParseMultipartForm(100000)
if err != nil { if err != nil {
@ -122,7 +122,7 @@ func upload(w http.ResponseWriter, r *http.Request) (int, error) {
// Create the file // Create the file
var outfile *os.File var outfile *os.File
if outfile, err = os.Create(r.URL.Path + hdr.Filename); nil != err { if outfile, err = os.Create(c.Path + r.URL.Path + hdr.Filename); nil != err {
w.Write([]byte(err.Error())) w.Write([]byte(err.Error()))
return http.StatusInternalServerError, err return http.StatusInternalServerError, err
} }