Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use multipart post for upload #4

Open
jo opened this issue Oct 17, 2013 · 0 comments
Open

Use multipart post for upload #4

jo opened this issue Oct 17, 2013 · 0 comments

Comments

@jo
Copy link

jo commented Oct 17, 2013

The library currently encodes the image inline as base64 in the post data.
It would be better to send a multipart/related request instead.

One way to do it would be to add an upload method, eg:

module Openphoto
  require 'net/http/post/multipart'

  class Client
    def upload photo, params = {}
      params["photo"] = UploadIO.new(File.open(photo), "image/jpeg", File.basename(photo))
      access_token = prepare_access_token
      request = Net::HTTP::Post::Multipart.new('/photo/upload.json', params)
      access_token.sign! request
      url = URI.parse @hostname
      response = Net::HTTP.start(url.host, url.port, :use_ssl => true) do |http|
        http.request request
      end
      response.extend Openphoto::Response
      response
    end
  end
end

(used in https://github.com/jo/trovebox-uploader)

One could also enhance the connect method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant