2

I need to POST the following curl command using Go

curl -X POST http://localhost:8001/routes/route_name -F "name=function" -F "config.file[1]=@my_file.lua"

I have been looking into multipart file upload examples, but I can't wrap my head around how to create a post with a nested field name (config.file is a config object with file as an array of strings) using CreateFormFile(key, val).

The problem I am having is according to the docs (https://pkg.go.dev/mime/multipart#Writer.WriteField) the WriteField API takes a field name and a value (path to file to post). I am not sure how to post a field name that is in a nested object e.g. CreateFormFile("config.file", filePath).

Anyone know how to convert the above curl command to Go using POST.

tiger_groove
  • 956
  • 2
  • 17
  • 46
  • https://stackoverflow.com/questions/20205796/post-data-using-the-content-type-multipart-form-data seems pretty complete example... please write some code and show us what you tried and where it went wrong. – erik258 Aug 12 '21 at 23:18
  • Does this answer your question? [POST data using the Content-Type multipart/form-data](https://stackoverflow.com/questions/20205796/post-data-using-the-content-type-multipart-form-data) – erik258 Aug 12 '21 at 23:18
  • So according to the docs (https://pkg.go.dev/mime/multipart#Writer.WriteField) the WriteField API takes a fieldname and a value (path to file to post). I am not sure how to post a fieldname that is in a nested object e.g. `CreateFormFile("config.file", filePath)`. The examples that are given seem to only cover cases of a flat object where the key is in the root level of the object, whereas I want to post the key that is in a nested value which is what the title of this question indicates. – tiger_groove Aug 16 '21 at 18:28

0 Answers0