multipart POST with Chef http_request resource

2019-08-09 05:18发布

问题:

Is there a way to do a multipart post with the Chef http_request resource? I have something like the following which posts the file contents, but I need to post form data along with it.

http_request 'post_file_and_form_data' do
  headers ({'Content-Type' => 'multipart/form-data'})
  url "http://myhost:2000/myapp/upload"
  action :post
  message lazy { ::File.read("/somewhere/myFile.yaml") }
end

回答1:

I'm not sure this is supported in the underlying Ruby standard library (Net::HTTP). I've seen most implementations that need this end up using the multipart-post gem. I'd suggest installing that and using it in your recipe, perhaps in a Ruby block.