Skip to content

API to post file #73

Closed
Closed

Description

@sferik

I’m trying to perform a multipart POST with the HTTP gem but I’m having trouble getting the headers and body right. We should include an example of how to do this in the README.

Activity

  1. tarcieri commented on Jan 30, 2014

    @tarcieri
    Member

    Or possibly an API like #post_file

  2. sferik commented on Jan 30, 2014

    @sferik
    ContributorAuthor

    @tarcieri Yes, that would be nice.

    FYI, I’ve been working on replacing Faraday with the HTTP gem on a branch in the Twitter gem. I’ve got pretty much everything working except for posting files (this branch also depends on JSON parsing, which I’ve hacked together in a local branch).

  3. tarcieri commented on Jan 30, 2014

    @tarcieri
    Member

    Nice, someone actually pinged me on Faraday support for the HTTP gem yesterday

  4. sferik commented on Jan 30, 2014

    @sferik
    ContributorAuthor

    That would be nice too.

    I haven’t done proper benchmarking but the Twitter test suite (about 900 examples that make about 368 HTTP requests) runs about 4X faster in the http branch than in master (with Faraday). Obviously, the bottleneck of any HTTP API wrapper is network latency but this seems like a pretty significant reduction in request overhead.

    I’d be curios to see how the performance would compare using an HTTP gem adapter for Faraday. I suspect it would be slower than using just the HTTP gem (sans Faraday). I think Faraday’s slowness is a result of having a middleware stack that each request must pass through.

    I do think writing a Faraday adapter would make it easier for people to try the HTTP gem in their existing clients.

  5. Asmod4n commented on Feb 3, 2014

    @Asmod4n
    Contributor

    https://github.com/nicksieger/multipart-post actually looks like it can be used anywhere.

  6. tarcieri commented on Mar 4, 2014

    @tarcieri
    Member

    I don't think this is required for 0.6

  7. sferik commented on Mar 4, 2014

    @sferik
    ContributorAuthor

    I agree, this is more of a nice-to-have for v0.6 but I think it’s a requirement for v1.0.

  8. modified the milestones: v1.0, v0.6 on Mar 4, 2014
  9. sferik commented on Mar 4, 2014

    @sferik
    ContributorAuthor

    I’ve moved this issue out of the v0.6 milestone and created a new v1.0 milestone.

  10. tarcieri commented on Mar 4, 2014

    @tarcieri
    Member

    Seems good

  11. ixti commented on May 25, 2014

    @ixti
    Member

    An issue with #post_file is that it will make API call look pretty strange when you need to upload more than one file or when you need to post some form values as well. I propose to stay with the same API we have now, we just need to recognize part of :form:

    HTTP.post(url, :form => {
      :title => "Foobar",
      :file => HTTP::UploadIO.new(path_to_file, optional_mime_type)
    })

    Something very similar to Faraday actually ;))

  12. sferik commented on May 26, 2014

    @sferik
    ContributorAuthor

    @ixti That would be acceptable to me. What is needed to support this?

  13. 5 remaining items

  14. ixti commented on Nov 12, 2014

    @ixti
    Member

    @sferik will try to jimp on this during this weekend.

  15. sferik commented on Nov 12, 2014

    @sferik
    ContributorAuthor

    @ixti \o/

  16. JuanitoFatas commented on Nov 12, 2014

    @JuanitoFatas
    Contributor

    @ixti 👍

  17. Asmod4n commented on Nov 12, 2014

    @Asmod4n
    Contributor

    @sferik what i was trying to say was multipart-post looks like it doesn't depent on anything and can be injected into any IO library, namely https://github.com/nicksieger/multipart-post/blob/master/lib/parts.rb seams to be independent of Net::HTTP and can be hooked into this gem :)

  18. sferik commented on Nov 12, 2014

    @sferik
    ContributorAuthor

    @Asmod4n Ah, very nice. :)

  19. ixti commented on Nov 17, 2014

    @ixti
    Member

    I have started working on this issue, but not yet finished :D Will finish during this week.
    We will not use multipart-post. Although it's really might be possible to couple it with HTTP gem, I dislike it's code and would like to come with our own solution.

  20. sferik commented on Nov 17, 2014

    @sferik
    ContributorAuthor

    @ixti Awesome! If this code is independent of the http gem, do you think it makes sense to package it as a separate gem (suggested name: http-multipart)? This would force us to have a clean separation and allow people to use it with other Ruby HTTP libraries.

  21. ixti commented on Nov 17, 2014

    @ixti
    Member

    @sferik Makes sense. Although I would like to first build it as part of HTTP gem - and then simply extract those classes out :D

    Re suggested name. Actually a more appropriate name will be http-form or probably http-form_data. A sneak peek to the API:

    # Usage inside with HTTP Gem:
    
    HTTP.post(some_url, :form => {
      :username => "ixti",
      :avatar => HTTP::FormData::File.new("/path/to/file.jpg"),
      :cv => HTTP::FormData::File.new(io, :filename => "cv.pdf")
    })
    
    # Standalone usage:
    
    form = HTTP::FormData.new({
      :username => "ixti",
      :avatar => HTTP::FormData::File.new("/path/to/file.jpg"),
      :cv => HTTP::FormData::File.new(io, :filename => "cv.pdf")
    })
    
    form.to_s # => returns HTTP request multipart body
  22. added and removed on Nov 17, 2014
  23. zackxu1 commented on Nov 10, 2016

    @zackxu1

    @ixti The above is really helpful. It would be even more helpful if it's in the README of the gem. Thank you.

  24. tarcieri commented on Nov 12, 2016

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions