1

I am trying to test a uploading service that supports multiple files uploading,and I found this:

golang POST data using the Content-Type multipart/form-data

that introduced how to create a request to upload a single file,but I need to upload multiple files,is there simple way to create this kind of request?

update:

please check line:38 and 39 in post:to support html5 multiple files uploading


line 38    files := m.File["myfiles"]
line 29      for i, _ := range files {

It seems that it needs to set single name for multiple file headers to stimulate the html5 multiple files uploading.

Community
  • 1
  • 1
Alex Luya
  • 9,412
  • 15
  • 59
  • 91

1 Answers1

3

For each file, call CreateFormFile to create the header for the file. Call Write on the writer returned from CreateFormFile one or more times to write data to the file. When done with all files, close the multipart writer.

The top answer in the linked question uploads two files, one named "image" and one named "key". The data for the "image" is copied from a file. The data for "key" is simply the bytes "KEY".

The field name is the first argument to CreateFormFile. If you want to upload multiple files with the same name, use the same name each time you call CreateFormFile.

Community
  • 1
  • 1
Simon Fox
  • 5,995
  • 1
  • 18
  • 22
  • Thanks,but I checked this https://www.socketloop.com/tutorials/upload-multiple-files-golang,under html5 multiple files uploading,it is one to multiple file headers,not multiple names for each header. – Alex Luya Sep 27 '14 at 00:54