Over a million developers have joined DZone.

Upload String Data As A File With Curb

DZone's Guide to

Upload String Data As A File With Curb

Free Resource
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 = 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'

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}