0

How do we POST an array of images using cURL?

I am using Grape API.

    requires :foo, type: Array do
      optional :bar, type: String
      optional :baz, type: Rack::Multipart::UploadedFile
    end

I want to test this using cURL. Request:

    curl -X POST -F "foo[][bar]=bar&foo[][baz][email protected]"\
        'http://localhost:5000/image_upload' 

The above request results in:

    [{"bar":"bar\u0026foo[][baz][email protected]"}]

The resulting format should be:

   [
      {bar: "bar1", baz: image_to_be_uploaded1},
      {bar: "bar2", baz: image_to_be_uploaded2}
   ]

Where as this POSTs image correctly. How do I send both the params in a single request?

      curl -X POST -F "foo[][baz][email protected]"\
       'http://localhost:5000/image_upload'

1 Answer 1

0

We have to specify the -F option (HTTP multipart POST data) twice

     curl -X POST -F "foo[][bar]=bar" -F "foo[][baz][email protected]"\
          'http://localhost:5000/image_upload'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.