Skip to content

Commit

Permalink
Fix filename calculation when header is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
mgomes committed Nov 12, 2020
1 parent f33476d commit f7432cc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ func fetchMetadata(uri string) (filesize uint64, filename string, err error) {
contentDisposition := resp.Header.Get("Content-Disposition")
_, params, err := mime.ParseMediaType(contentDisposition)
if err != nil {
return filesize, "", nil
filename = filenameFromURI(uri)
return filesize, filename, nil
}
filename = params["filename"]

// No filename specified in the header; use the pathname
if filename == "" {
splitUri := strings.Split(uri, "/")
filename = splitUri[len(splitUri)-1]
filename = filenameFromURI(uri)
}

return
Expand Down Expand Up @@ -142,6 +142,11 @@ func downloadPartFilename(part int) string {
return fmt.Sprintf("download.part%d", part)
}

func filenameFromURI(uri string) string {
splitUri := strings.Split(uri, "/")
return splitUri[len(splitUri)-1]
}

func concatFiles(filename string, parts int) {
var readers []io.Reader

Expand Down

0 comments on commit f7432cc

Please sign in to comment.