mirror of https://github.com/Xhofe/alist
				
				
				
			
		
			
				
	
	
		
			22 lines
		
	
	
		
			488 B
		
	
	
	
		
			Go
		
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			488 B
		
	
	
	
		
			Go
		
	
	
| 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
 | |
| }
 |