Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

file upload support to make http fun #77

Closed
timwaters opened this Issue · 14 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

+1

@mickey

+1

@mattpolito

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

@mickey

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

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

@rtdp

+1 to file upload support

@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
@maletor

The dependency works the other way around now.

https://github.com/jwagener/httmultiparty

@radar

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'
@narzero

+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.