From ecf58d57fec6aa0b0676b254e5f7edd211288662 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 21 Sep 2021 10:07:10 +0100 Subject: [PATCH] fix: manually parse the content disposition to preserve directories fixes https://github.com/ipfs/go-ipfs/issues/8445 This commit was moved from ipfs/go-ipfs-files@55e9e3fbacdfd1f4c99ca3638c03e1c92f23f9ae --- files/multipartfile.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/files/multipartfile.go b/files/multipartfile.go index d4593ad6c..24211cdc0 100644 --- a/files/multipartfile.go +++ b/files/multipartfile.go @@ -110,7 +110,12 @@ func (w *multipartWalker) nextFile() (Node, error) { // fileName returns a normalized filename from a part. func fileName(part *multipart.Part) string { - filename := part.FileName() + v := part.Header.Get("Content-Disposition") + _, params, err := mime.ParseMediaType(v) + if err != nil { + return "" + } + filename := params["filename"] if escaped, err := url.QueryUnescape(filename); err == nil { filename = escaped } // if there is a unescape error, just treat the name as unescaped