file upload support to make http fun #77

Closed
timwaters opened this Issue Mar 14, 2011 · 21 comments

Comments

Projects
None yet
@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

This comment has been minimized.

Show comment
Hide comment

lou commented Apr 28, 2011

+1

@mickey

This comment has been minimized.

Show comment
Hide comment

mickey commented Apr 28, 2011

+1

@mattpolito

This comment has been minimized.

Show comment
Hide comment
@mattpolito

mattpolito Apr 28, 2011

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

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

@mickey

This comment has been minimized.

Show comment
Hide comment
@mickey

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

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

This comment has been minimized.

Show comment
Hide comment
@mattpolito

mattpolito Apr 29, 2011

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

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

@jasonroelofs

This comment has been minimized.

Show comment
Hide comment
@jasonroelofs

jasonroelofs Jan 18, 2012

Contributor

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.

Contributor

jasonroelofs commented Jan 18, 2012

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

This comment has been minimized.

Show comment
Hide comment
@maletor

maletor Feb 16, 2012

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

maletor commented Feb 16, 2012

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

@rtdp

This comment has been minimized.

Show comment
Hide comment
@rtdp

rtdp Feb 21, 2012

+1 to file upload support

rtdp commented Feb 21, 2012

+1 to file upload support

@onedanshow

This comment has been minimized.

Show comment
Hide comment

+1

@jnunemaker

This comment has been minimized.

Show comment
Hide comment
@jnunemaker

jnunemaker Apr 22, 2012

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.

Owner

jnunemaker commented Apr 22, 2012

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

This comment has been minimized.

Show comment
Hide comment
@maletor

maletor Apr 22, 2012

The dependency works the other way around now.

https://github.com/jwagener/httmultiparty

maletor commented Apr 22, 2012

The dependency works the other way around now.

https://github.com/jwagener/httmultiparty

@radar

This comment has been minimized.

Show comment
Hide comment
@radar

radar Mar 21, 2014

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'

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/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

This comment has been minimized.

Show comment
Hide comment

narzero commented Jul 28, 2014

+1

@trkrameshkumar

This comment has been minimized.

Show comment
Hide comment
@icalvete

This comment has been minimized.

Show comment
Hide comment

+1

@ajahongir

This comment has been minimized.

Show comment
Hide comment

+1

@zbeat

This comment has been minimized.

Show comment
Hide comment
@zbeat

zbeat Jan 26, 2017

+1

We implemented @jwagener's HTTMultiParty as a workaround years ago, and it's been working perfectly ever since. However, as that is an unmaintained project, this feels like a good time to revisit native multipart support in HTTParty.

zbeat commented Jan 26, 2017

+1

We implemented @jwagener's HTTMultiParty as a workaround years ago, and it's been working perfectly ever since. However, as that is an unmaintained project, this feels like a good time to revisit native multipart support in HTTParty.

@naveengowd

This comment has been minimized.

Show comment
Hide comment
@naveengowd

naveengowd Feb 2, 2017

By using the RestClient gem we can easily handle the file uploads, but make sure that you install the rest-client gem.

And the code in controller as like below,

  res = RestClient::Request.execute(
      method: :post,
      url: "http://www.your_url.com",
      payload: params,

      headers: {
          'Content-Type' => "multipart/form-data",
          Authorization: "some_key",
          :Accept => "*/*"
      }

  )

By using the RestClient gem we can easily handle the file uploads, but make sure that you install the rest-client gem.

And the code in controller as like below,

  res = RestClient::Request.execute(
      method: :post,
      url: "http://www.your_url.com",
      payload: params,

      headers: {
          'Content-Type' => "multipart/form-data",
          Authorization: "some_key",
          :Accept => "*/*"
      }

  )
@ntnmrndn

This comment has been minimized.

Show comment
Hide comment
@ntnmrndn

ntnmrndn Jun 27, 2017

Why the close?

Why the close?

@jnunemaker

This comment has been minimized.

Show comment
Hide comment
@jnunemaker

jnunemaker Jun 27, 2017

Owner

I explained why in the comment before the close. #77 (comment)

Owner

jnunemaker commented Jun 27, 2017

I explained why in the comment before the close. #77 (comment)

@zbeat zbeat referenced this issue Aug 16, 2017

Closed

Multipart support #52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment