Skip to content

Commit

Permalink
Fix upload not working issue
Browse files Browse the repository at this point in the history
Fix the issue that the web upload was not working. The issue was coming
from overwriting the multibody reader with r.Body.
  • Loading branch information
grisu48 committed Aug 9, 2022
1 parent fb036c4 commit 9218427
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions cmd/pastad/pastad.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,21 +390,22 @@ func ReceivePasta(r *http.Request) (Pasta, error) {
pasta.Id = ""
return pasta, err
}
}
// Check if the input is coming from the POST form
inputs := r.URL.Query()["input"]
if len(inputs) > 0 && inputs[0] == "form" {
// Copy reader, as r.FromValue consumes it's contents
defer r.Body.Close()
reader = r.Body
if content := r.FormValue("content"); content != "" {
reader = io.NopCloser(strings.NewReader(content))
} else {
// Check if the input is coming from the POST form
inputs := r.URL.Query()["input"]
if len(inputs) > 0 && inputs[0] == "form" {
// Copy reader, as r.FromValue consumes it's contents
defer r.Body.Close()
reader = r.Body
if content := r.FormValue("content"); content != "" {
reader = io.NopCloser(strings.NewReader(content))
} else {
pasta.Id = "" // Empty pasta
return pasta, nil
}
} else {
pasta.Id = "" // Empty pasta
return pasta, nil
reader = r.Body
}
} else {
reader = r.Body
}
defer reader.Close()

Expand Down

0 comments on commit 9218427

Please sign in to comment.