Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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:


#!/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)
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}