Skip to content

file upload support to make http fun #77

Closed
timwaters opened this Issue Mar 14, 2011 · 16 comments
@timwaters

Pretty much every ruby http library does not support file uploads. This is wrong, and leads people to write their own libraries, scripts, subroutines and hacks, often failing.

Httparty, being the best http library should support this.

Please make http fun, and support file uploads.

Thanks

@lou
lou commented Apr 28, 2011

+1

@mickey
mickey commented Apr 28, 2011

+1

@mattpolito

It is open source... sounds like a perfect time for you to jump in.

@mickey
mickey commented Apr 28, 2011

Hey Matt,
You perfectly right on this one,
I actually saw there's some good parts that could be use for a great file upload support :

I already have a prototype working locally with some part here and here + some patches, I'll try to add a good testing suite and make a pull request for review.

@mattpolito

@mickey it's really great to hear you want to take that on!

@jasonroelofs

As a quick FYI for those wondering about this, I've monkey-patched basic support of #body_stream with the following:

module HTTParty
  class Request
    private

    def setup_raw_request
      @raw_request = http_method.new(uri.request_uri)
      if body
        if body.respond_to?(:read)
          @raw_request.body_stream = body
        else
          @raw_request.body = body
        end
      end
      @raw_request.initialize_http_header(options[:headers])
      @raw_request.basic_auth(username, password) if options[:basic_auth]
      setup_digest_auth if options[:digest_auth]
    end

  end
end

If you give :body an IO object, this will pick that up and run a streaming push instead of raw file data.

@maletor
maletor commented Feb 16, 2012

Yes this is good. A little test and this should be good to go.

@rtdp
rtdp commented Feb 21, 2012

+1 to file upload support

@onedanshow

+1

@jnunemaker
Owner

If this requires another dependency, I'd rather see it done as a plugin in a separate gem. I'm happy to add hooks and such if that is what is needed. Closing this for now.

@jnunemaker jnunemaker closed this Apr 22, 2012
@maletor
maletor commented Apr 22, 2012

The dependency works the other way around now.

https://github.com/jwagener/httmultiparty

@radar
radar commented Mar 21, 2014

I know this issue is fairly old, but it ranks highly in Google searches, so I thought I should update. jwagener-soundcloud/httmultiparty#11 indicates that while the file upload features of the library work, it falls apart when you want to pass more parameters than just the file that's being uploaded. I addressed this in jwagener-soundcloud/httmultiparty#30.

If @jwagener doesn't merge this due to whatever reason, I'm happy to maintain a fork of that library on my personal GitHub.

gem 'httmultiparty', github: 'radar/httmultiparty', branch: 'master'
@narzero
narzero commented Jul 28, 2014

+1

@icalvete

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.