Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
53735263
Commit
53735263
authored
Nov 16, 2014
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands/http: Parse multipart files into req.Files()
parent
4b9fa9c9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
10 deletions
+17
-10
commands/http/parse.go
commands/http/parse.go
+17
-10
No files found.
commands/http/parse.go
View file @
53735263
...
@@ -2,6 +2,7 @@ package http
...
@@ -2,6 +2,7 @@ package http
import
(
import
(
"errors"
"errors"
"mime"
"net/http"
"net/http"
"strings"
"strings"
...
@@ -49,10 +50,6 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
...
@@ -49,10 +50,6 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
// count the number of provided argument values
// count the number of provided argument values
valCount
:=
len
(
stringArgs
)
valCount
:=
len
(
stringArgs
)
// TODO: add total number of parts in request body (instead of just 1 if body is present)
if
r
.
Body
!=
nil
&&
r
.
ContentLength
!=
0
{
valCount
+=
1
}
args
:=
make
([]
interface
{},
valCount
)
args
:=
make
([]
interface
{},
valCount
)
...
@@ -81,11 +78,6 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
...
@@ -81,11 +78,6 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
}
else
{
}
else
{
break
break
}
}
}
else
{
// TODO: create multipart streams for file args
args
[
valIndex
]
=
r
.
Body
valIndex
++
}
}
}
}
...
@@ -94,7 +86,22 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
...
@@ -94,7 +86,22 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
return
nil
,
err
return
nil
,
err
}
}
req
,
err
:=
cmds
.
NewRequest
(
path
,
opts
,
args
,
cmd
,
optDefs
)
// create cmds.File from multipart/form-data contents
contentType
:=
r
.
Header
.
Get
(
contentTypeHeader
)
mediatype
,
_
,
err
:=
mime
.
ParseMediaType
(
contentType
)
if
err
!=
nil
{
return
nil
,
err
}
var
f
*
cmds
.
MultipartFile
if
mediatype
==
"multipart/form-data"
{
f
=
&
cmds
.
MultipartFile
{
Mediatype
:
mediatype
}
f
.
Reader
,
err
=
r
.
MultipartReader
()
if
err
!=
nil
{
return
nil
,
err
}
}
req
,
err
:=
cmds
.
NewRequest
(
path
,
opts
,
args
,
f
,
cmd
,
optDefs
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment