R
R
recloudor2015-12-06 07:11:09
go
recloudor, 2015-12-06 07:11:09

How to accept a file?

What is the problem:
1) An error pops up - http not such ...
Give a working example for drag & drop please

func fileUploadHandler(w http.ResponseWriter, r *http.Request) { 
    r.ParseMultipartForm(0) 
    file, handler, err := r.FormFile("file") 
    if err != nil { 
        fmt.Println(err) 
        return 
    } 
    defer file.close()
    f, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666) 
    if err != nil { 
        fmt.Println(err) 
        return 
    } 
    defer f.Close() 
    io.Copy(f, file)
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question