Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ruby OAuth file uploads
# patch OAuth class to be able to create multipart requests (required for image uploading)
# NOTE that for my purpose I simply made it "auto-sensing" that an image is passed and
# only then creates a multipart body. You may simply want to use some flag instead or whatever.
module OAuth
class Consumer
alias_method :create_default_http_request, :create_http_request
protected
def create_http_request(http_method, path, *arguments)
# CHANGE THIS -- I only did this because it was for a quick-and-dirty script that had to upload pictures
if http_method == :post && path.include?('/assets')
create_multipart_http_request(http_method, path, *arguments)
else
create_default_http_request(http_method, path, *arguments)
end
end
def create_multipart_http_request(http_method, path, *arguments)
image_path = arguments.shift
Net::HTTP::Post::Multipart.new(path, "uploaded_data" => UploadIO.new(File.open(image_path), "image/jpeg", "print_ad.jpg"))
end
end
end
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.