8

I'm trying to do file uploads with ruby 1.8 and it seems like there are no good out-of-the-box solutions. They all seem to need some 3rd party patch or fork of a project to work. I would use mechanize but I actually need to interface with an xml api and mechanize seems to be made specifically for dealing directly with webpages. I've tried RestClient but it doesn't have that functionality for multipart forms out of the box, you have to use a fork of the project to get it to work. Similar situations seem to exist for Net:HTTP I'm thinking curb would be the way to go since I may want to use multicurl anyways for some other things I plan to do. However, on my windows machine I can't seem to install the curb gem. gem install curb gives an error saying I need to specify where the curl library lives.. I've tried passing options to extconf but no luck so far. Here is the output of gem install curb without any options

C:\ruby\lib\ruby\gems\1.8\gems\curb-0.5.4.0>gem install curb
Building native extensions.  This could take a while...
ERROR:  Error installing curb:
        ERROR: Failed to build gem native extension.

C:/ruby/bin/ruby.exe extconf.rb
checking for curl-config... no
checking for main() in curl.lib... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/ruby/bin/ruby
        --with-curl-dir
        --without-curl-dir
        --with-curl-include
        --without-curl-include=${curl-dir}/include
        --with-curl-lib
        --without-curl-lib=${curl-dir}/lib
        --with-curllib
        --without-curllib
extconf.rb:12:   Can't find libcurl or curl/curl.h (RuntimeError)

  Try passing --with-curl-dir or --with-curl-lib and --with-curl-include
  options to extconf.


Gem files will remain installed in C:/ruby/lib/ruby/gems/1.8/gems/curb-0.5.4.0 for inspection.
Results logged to C:/ruby/lib/ruby/gems/1.8/gems/curb-0.5.4.0/ext/gem_make.out

Any ideas how I can get this to work?

Matt Wolfe
  • 8,924
  • 8
  • 60
  • 77
  • My eventual solution was to just use ruby rest-client which has full support for file uploads. To get this simply add http://gems.github.com to your sources (if you haven't already) then do gem install rest-client From there you can do multipart post with as many fields/files as you want.. Example here: http://rdoc.info/projects/archiloque/rest-client This client works great, highly recommend it. – Matt Wolfe Jul 06 '10 at 18:32

11 Answers11

18

Matt,

I've had trouble installing the curb gem in Windows before. In trying to see how others had solved this I came across a lot of questions and not very many solutions. Having to do it again tonight I decided to document my steps and post the results: http://beginrescue.blogspot.com/2010/07/installing-curb-with-ruby-191-in.html

Sorry for the blogspam, hope this is useful for somebody.

pete

phiggy
  • 898
  • 8
  • 9
  • I get error "invalid option: --with-curl-lib". May be do you now how can I fix it ? – ceth Nov 13 '12 at 18:34
  • I have this as well. The answer was to include an additional double-dash (--), i.e. gem install curb -- -- --with-curl-lib[...] (see http://www.basson.at/blog/installing-curb-on-windows) – Ben Jul 12 '14 at 10:00
4

Ultimately, in win7 with ruby 1.9.1 the following worked for me (where paths need to be updated to reflect the location (and version) of your curl version (which can be obtained via http://curl.haxx.se/download.html#Win32))

gem install curb -- --with-curl-lib="C:/curl/curl-7.21.1-devel-mingw32/bin" --with-curl-include="C:/curl/curl-7.21.1-devel-mingw32/include"

This did take a few minutes to process, so be patient.

Evan
  • 835
  • 1
  • 6
  • 14
  • 1
    I get error "invalid option: --with-curl-lib". May be do you now how can I fix it ? – ceth Nov 13 '12 at 18:36
3

I used Evan's install config in his answer with the correct libcurl binary from the wizard: http://curl.haxx.se/dlwiz/

gem install curb -- --with-curl-lib="C:/curl/curl-7.21.1-devel-mingw32/bin" --with-curl-include="C:/curl/curl-7.21.1-devel-mingw32/include"

This worked for me on win XP 64 bit.

Make sure to select libcurl with the description about being the binary for libcurl software development.

JimBtek
  • 106
  • 4
  • I've tried pretty much everything, and I think I couldn't get it to work becsue of the version I of curl I had, the wizard gave me the windows 32-bit version, which is odd as i'm on 64-bit windows, but it worked to thanks for sharing the link to the wizard! – Ben Oct 19 '12 at 11:42
  • i had to throw in a "--platform=ruby" after the curb and my version number differed, but otherwise this worked for me (curb 0.8.6 / Ruby 2.1.4 / curl 7.39.0) – amenthes Jan 07 '15 at 23:39
1

Looking at the underlying issue you are trying to solve. I was looking for a multpart-post client before and spent a lot of time trying out diffrent gems/tools. The only one i found that worked satisfactory was Nick Siegers multipart-post gem

It was very straightforward to use, I highly recommend it.

Here is sample code i made for my test

require "rubygems"
require 'net/http/post/multipart'

url = URI.parse('http://localhost:3000/mytest/1.xml')
File.open("c:/temp/readme.txt") do |jpg|
  req = Net::HTTP::Put::Multipart.new url.path,
    "mytest[attachment]" => UploadIO.new(jpg, "text/plain", "c:/temp/readme.txt")
  res = Net::HTTP.start(url.host, url.port) do |http|
    http.request(req)
  end
  puts res.inspect
end
Mikael R
  • 11
  • 1
  • I don't think this will allow multiple file uploads in a single request will it. Otherwise it looks like a good way to upload a single file in a request – Matt Wolfe Oct 06 '09 at 18:57
1

For Windows 8 the command was:

gem install curb -- --with-curl-lib=C:/Utils/curl-7.32.0-dev/lib64 --with-curl-include=C:/Utils/curl-7.32.0-dev/include

And it nearly installs. Now there are "undefined reference" warnings/errors

rupweb
  • 3,052
  • 1
  • 30
  • 57
1

That works too, on Windows 10 x64:

gem install curb -- --with-curl-lib="C:/Users/WindowsVM/binaries/curl-7.40.0-devel-mingw64/lib64" --with-curl-include="C:/Users/WindowsVM/binaries/curl-7.40.0-devel-mingw64/include"

1

As I commented already, I did find a solution which was simply using the rest-client provided in the github gems.. gem install rest-client will get the job done. From there you can do a multipart post which can contain 1 or more files.. It has all the flexibility one could need in a rest-client. See the documentation here: http://rdoc.info/projects/archiloque/rest-client for examples on how to use it.

The only thing I found that it didn't do correctly was parsing cookies. The cookies my company uses can have equal signs in the values and it doesn't parse them correctly. I had put in some hacks to get around the issue but eventually that came back to bite me.. So just the other day I started analyzing the code from Mechanize/WEBrick and was able to utilize the CookieJar from Mechanize to manage cookies from the rest-client.. Hopefully I can get the author of the rest-client to build this functionality into the rest-client so others won't have the same problems I had..

Matt Wolfe
  • 8,924
  • 8
  • 60
  • 77
0

When you say you passed configuration options to extconf.rb, did you mean in the gem install command?

If not, I believe it would be something along the lines of

gem install curb -- --with-curl-dir=dir

It might be a different config option, but the -- is that bit you need to pass it configure options.

Robert Rouse
  • 4,801
  • 1
  • 19
  • 19
  • The README file says to pass options like this: rake install EXTCONF_OPTS='--with-curl-dir=/path/to/libcurl --prefix=/what/ever' So I did something similar: rake install EXTCONF_OPTS='--with-curl-dir=c:/curl' I tried a few variations of that syntax/quotes, and also tried specifying explicitly using with-curl-dir/with-curl-include fields instead of with-curl-dir No luck, and it doesn't appear very many people are running curl with ruby online so it may not be a good choice (unfortunately) – Matt Wolfe Oct 06 '09 at 19:01
0

I tried all of the solutions above and nothing worked, I gave up but luckily I later stumbled upon this post http://jooglar.com/edely/content/installing-libcurl-ruby-windows and the instructions there worked perfectly.

Here are the directions, in case the website goes belly up:


1. Download the "libcurl" version of the library
From http://curl.haxx.se/dlwiz/?type=lib

2. Install wherever, but the path cannot have spaces.
Be sure that when you unzip the file, you find the directories “bin” and “include”

3. Add the libcurl path (ending in /bin;) to the system PATH variable
WARNING: USE / INSTEAD OF \ in the PATH. No spaces allowed in the path. For example: C:/curl/curl-7.26.0-devel-mingw32/bin;

4. Install the gem
WARNING: AGAIN, USE / INSTEAD OF \ in the PATH. See above.

Example command: gem install curb -- --with-curl-lib=C:/curl/curl-7.26.0-devel-mingw32/bin --with-curl-include=C:/curl/curl-7.26.0-devel-mingw32/include


[NB: Note the standalone -- before --with-..., this was a gotcha for me.]

At this point, it should work. It worked for me. If it doesn't, you could try the rest of the instructions:


If it does not work, copy the following .dll files to the ruby/bin directory and run again the previous command.

  • libcurl.dll
  • libssl32.dll
  • libeay32.dll

Also, if that does not work...update the DevKit and run again the previous command. Download the latest version and from a console go to the DevKit directory and run ruby dk.rb install --force

San Diago
  • 1,030
  • 1
  • 12
  • 26
0

Execute Below command and its works

gem install curb --platform=mswin32

AMIC MING
  • 6,306
  • 6
  • 46
  • 62
0

after a lots of time spending on it, I give up...

The answers given above don't work for me, and some of the "curl" links are broken, I can't even download from the official web-site.

what I want is quite simple: install curb gem on cygwin.

Now I switched to VirtalBox, and installed a Ubuntu server on it. then, I install it in 20 minutes without any problems.

So, People working under cygwin, let's switch to Virtual Machine!

Siwei
  • 19,858
  • 7
  • 75
  • 95