Module: Wrest::Multipart
- Included in:
- Uri
- Defined in:
- lib/wrest/multipart.rb
Overview
To enable Multipart support, use
require 'wrest/multipart'
Multipart support is currently only available on Net::Http It depends on the multipart-post gem being available. To install multipart-post
(sudo) gem install multipart-post
The methods in this module are mixed into Wrest::Uri.
Instance Method Summary collapse
-
#post_multipart(parameters = {}, headers = {}, &block) ⇒ Object
Makes a multipart/form-data encoded POST request to this URI.
-
#post_multipart_async(parameters = {}, headers = {}, &block) ⇒ Object
Makes a multipart/form-data encoded POST request to this URI.
-
#put_multipart(parameters = {}, headers = {}, &block) ⇒ Object
Makes a multipart/form-data encoded PUT request to this URI.
-
#put_multipart_async(parameters = {}, headers = {}, &block) ⇒ Object
Makes a multipart/form-data encoded PUT request to this URI.
Instance Method Details
#post_multipart(parameters = {}, headers = {}, &block) ⇒ Object
Makes a multipart/form-data encoded POST request to this URI. This is a convenience API that mimics a multipart form being posted; some allegedly RESTful APIs like FCBK require this for file uploads.
File.open('/path/to/image.jpg') do |file|
'http://localhost:3000/uploads'.to_uri.post_multipart('file' => UploadIO.new(file, "image/jpg", '/path/to/image.jpg'))
end
37 38 39 |
# File 'lib/wrest/multipart.rb', line 37 def post_multipart(parameters = {}, headers = {}, &block) Http::PostMultipart.new(self, parameters, headers, block ? .merge(:callback_block => block) : ).invoke end |
#post_multipart_async(parameters = {}, headers = {}, &block) ⇒ Object
Makes a multipart/form-data encoded POST request to this URI. This is a convenience API that mimics a multipart form being posted; some allegedly RESTful APIs like FCBK require this for file uploads.
File.open('/path/to/image.jpg') do |file|
'http://localhost:3000/uploads'.to_uri.post_multipart_async('file' => UploadIO.new(file, "image/jpg", '/path/to/image.jpg'))
end
Note: post_multipart_async does not return a response and the response should be accessed through callbacks. This implementation of asynchronous post_multipart is currently in alpha. Hence, it should not be used in production.
51 52 53 |
# File 'lib/wrest/multipart.rb', line 51 def post_multipart_async(parameters = {}, headers = {}, &block) ([:asynchronous_backend] || Wrest::AsyncRequest.default_backend).execute(Http::PostMultipart.new(self, parameters, headers, block ? .merge(:callback_block => block) : )) end |
#put_multipart(parameters = {}, headers = {}, &block) ⇒ Object
Makes a multipart/form-data encoded PUT request to this URI. This is a convenience API that mimics a multipart form being put. I sincerely hope you never need to use this.
57 58 59 |
# File 'lib/wrest/multipart.rb', line 57 def put_multipart(parameters = {}, headers = {}, &block) Http::PutMultipart.new(self, parameters, headers, block ? .merge(:callback_block => block) : ).invoke end |
#put_multipart_async(parameters = {}, headers = {}, &block) ⇒ Object
Makes a multipart/form-data encoded PUT request to this URI. This is a convenience API that mimics a multipart form being put. I sincerely hope you never need to use this.
Note: put_multipart_async does not return a response and the response should be accessed through callbacks This implementation of asynchronous put_multipart is currently in alpha. Hence, it should not be used in production.
66 67 68 |
# File 'lib/wrest/multipart.rb', line 66 def put_multipart_async(parameters = {}, headers = {}, &block) ([:asynchronous_backend] || Wrest::AsyncRequest.default_backend).execute(Http::PutMultipart.new(self, parameters, headers, block ? .merge(:callback_block => block) : )) end |