File size: 488 Bytes
7107f0b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
package http
import (
"fmt"
"mime"
)
func parseFilenameFromContentDisposition(contentDisposition string) (string, error) {
if contentDisposition == "" {
return "", fmt.Errorf("Content-Disposition is empty")
}
_, params, err := mime.ParseMediaType(contentDisposition)
if err != nil {
return "", err
}
filename := params["filename"]
if filename == "" {
return "", fmt.Errorf("filename not found in Content-Disposition: [%s]", contentDisposition)
}
return filename, nil
}
|