diff --git a/internal/api/qbit.go b/internal/api/qbit.go index 3a5f8fc..19ab21b 100644 --- a/internal/api/qbit.go +++ b/internal/api/qbit.go @@ -1,6 +1,7 @@ package api import ( + "mime" "net/http" "net/url" "os" @@ -113,9 +114,18 @@ func (s *Server) handleQBitTransferInfo(w http.ResponseWriter, r *http.Request) } func (s *Server) handleQBitAdd(w http.ResponseWriter, r *http.Request) { - if err := r.ParseMultipartForm(8 << 20); err != nil { // 8 MB; torrent files are typically < 1 MB - http.Error(w, err.Error(), http.StatusBadRequest) - return + contentType := r.Header.Get("Content-Type") + mediaType, _, _ := mime.ParseMediaType(contentType) + if mediaType == "multipart/form-data" { + if err := r.ParseMultipartForm(8 << 20); err != nil { // 8 MB; torrent files are typically < 1 MB + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + } else { + if err := r.ParseForm(); err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } } category := strings.TrimSpace(r.PostFormValue("category"))