Standard library / mime/multipart
multipart.Part.FileName()
Return the platform-dependent basename of the supplied filename parameter. Do not use this alone to establish safe filesystem containment. Expected stdout: 'demo.txt\n'.
Formal Syntax & Structure
go syntaxgo
func (p *Part) FileName() stringReturn Value
string
Platform-dependent basename of filename parameter, or empty string.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt" "io" "mime/multipart")
func main() { var b bytes.Buffer w := multipart.NewWriter(&b) check(w.SetBoundary("demo")) check(w.WriteField("name", "Ada")) f := must(w.CreateFormFile("file", "demo.txt")) must(io.WriteString(f, "hello")) check(w.Close()) r := multipart.NewReader(&b, w.Boundary()) part := must(r.NextPart()) check(part.Close()) fmt.Println(must(r.NextPart()).FileName())}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}