NeoZephyr / Post-It-Note

0 stars 0 forks source link

HTTP request and response #12

Open NeoZephyr opened 2 years ago

NeoZephyr commented 2 years ago
file, header, err := req.FormFile("file")
defer file.Close()
content, err := ioutil.ReadAll(file)
filename := header.Filename
buf := new(bytes.Buffer)
bodyWriter := multipart.NewWriter(buf)
fileWriter, err := bodyWriter.CreateFormFile("file", fileName)
io.Copy(fileWriter, bytes.NewReader(data))
bodyWriter.Close()
req.Header.Set("Content-Type", bodyWriter.FormDataContentType())