Skip to content
This repository

file upload support to make http fun #77

Closed
timwaters opened this Issue · 13 comments
Tim Waters

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

louis cuny
lou commented

+1

Michael Bensoussan

+1

Matt Polito

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

Michael Bensoussan

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.

Matt Polito

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

Jason Roelofs

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.

Ellis Berner

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

Ratnadeep Deshmane

+1 to file upload support

Daniel Dixon

+1

John Nunemaker
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.

John Nunemaker jnunemaker closed this
Ellis Berner

The dependency works the other way around now.

https://github.com/jwagener/httmultiparty

Ryan Bigg
radar commented

I know this issue is fairly old, but it ranks highly in Google searches, so I thought I should update. jwagener/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/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'
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.