Upload String Data As A File With Curb
Join the DZone community and get the full member experience.Join For Free
Uploading a local file with Curb is easy, but some times you have the data in a Ruby string. You can use this code then:
#!/usr/bin/ruby require 'rubygems' require 'curb' c = Curl::Easy.new("http://localhost/") c.multipart_form_post = true post_field = Curl::PostField.content('fieldname', 'raw contents of file') post_field.remote_file = 'nameoffile.txt' post_field.content_type = 'application/octet-stream' c.http_post(post_field)
Data (computing) Strings Upload Data Types
Opinions expressed by DZone contributors are their own.