6

Golang multipart/form-data File Upload · GitHub

 1 year ago
source link: https://gist.github.com/andrewmilson/19185aab2347f6ad29f5
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Golang multipart/form-data File Upload · GitHub

Instantly share code, notes, and snippets.

Golang multipart/form-data File Upload

Thanks!

This example is the best. Thanks!

Will this code use sendfile to achieve zero copy?

Спасибо)

Thank you soooooooooo much!!

thanks!! :)

alright!

Thank you

+1

Do you have any ideas how to send a zip file using multipart writer?

Thanks!! Much appreciated!

Thanks! it's working well.

Thanks!

Thank you <3

Thanks.

Thanks +1

it works

it works

Thanks!

Nice work

Thx, nice gist

Solid

thanks!

if, for whatever reason you need to specify the content type of a part - here's the excerpt:

body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
h := make(textproto.MIMEHeader)
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, "file", "myfile.xml"))
h.Set("Content-Type", "text/xml")
part, _ := writer.CreatePart(h)

otherwise this code is absolutely perfect, thanks !

thanks!

Is it possible to compile this in an executable and then whenever you run that '.exe' the server will start to listen on incoming requests?

Hello, if I need to upload a zip file as form-data in POST request body, I am able to find this,

zipWriter := zip.NewWriter(buf)
zipFile, err := zipWriter.Create(fileName)

Unlike multipart.Writer, in case of zip.Writer I can't find any option to create form file in a key-value fashion.

How can I achieve this for zip as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK