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

  • 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:

require 'rubygems'
require 'curb'

c ="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'