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-cmds
Commits
ae5259f0
Commit
ae5259f0
authored
Feb 02, 2015
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: URL escape filenames in multipart files, resolves #654
parent
34aee4d7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
3 deletions
+11
-3
files/multipartfile.go
files/multipartfile.go
+7
-1
http/multifilereader.go
http/multifilereader.go
+4
-2
No files found.
files/multipartfile.go
View file @
ae5259f0
...
...
@@ -4,6 +4,7 @@ import (
"mime"
"mime/multipart"
"net/http"
"net/url"
)
const
(
...
...
@@ -67,7 +68,12 @@ func (f *MultipartFile) NextFile() (File, error) {
}
func
(
f
*
MultipartFile
)
FileName
()
string
{
filename
,
err
:=
url
.
QueryUnescape
(
f
.
Part
.
FileName
())
if
err
!=
nil
{
// if there is a unescape error, just treat the name as unescaped
return
f
.
Part
.
FileName
()
}
return
filename
}
func
(
f
*
MultipartFile
)
Read
(
p
[]
byte
)
(
int
,
error
)
{
...
...
http/multifilereader.go
View file @
ae5259f0
...
...
@@ -6,6 +6,7 @@ import (
"io"
"mime/multipart"
"net/textproto"
"net/url"
"sync"
files
"github.com/jbenet/go-ipfs/commands/files"
...
...
@@ -74,11 +75,12 @@ func (mfr *MultiFileReader) Read(buf []byte) (written int, err error) {
// write the boundary and headers
header
:=
make
(
textproto
.
MIMEHeader
)
filename
:=
url
.
QueryEscape
(
file
.
FileName
())
if
mfr
.
form
{
contentDisposition
:=
fmt
.
Sprintf
(
"form-data; name=
\"
file
\"
; filename=
\"
%s
\"
"
,
file
.
FileN
ame
()
)
contentDisposition
:=
fmt
.
Sprintf
(
"form-data; name=
\"
file
\"
; filename=
\"
%s
\"
"
,
file
n
ame
)
header
.
Set
(
"Content-Disposition"
,
contentDisposition
)
}
else
{
header
.
Set
(
"Content-Disposition"
,
fmt
.
Sprintf
(
"file; filename=
\"
%s
\"
"
,
file
.
FileN
ame
()
))
header
.
Set
(
"Content-Disposition"
,
fmt
.
Sprintf
(
"file; filename=
\"
%s
\"
"
,
file
n
ame
))
}
if
file
.
IsDirectory
()
{
...
...
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