DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Troels has posted 3 posts at DZone. View Full User Profile

Upload String Data As A File With Curb

05.19.2009
| 6034 views |
  • submit to reddit
        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)