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
39 40 41 42 |
# File 'lib/wrest/multipart.rb', line 39 def post_multipart(parameters = {}, headers = {}, &block) Http::PostMultipart.new(self, parameters, headers, block ? @options.merge(callback_block: block) : @options).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.
54 55 56 57 58 59 60 |
# File 'lib/wrest/multipart.rb', line 54 def post_multipart_async(parameters = {}, headers = {}, &block) (@options[:asynchronous_backend] || Wrest::AsyncRequest.default_backend) .execute( Http::PostMultipart.new(self, parameters, headers, block ? @options.merge(callback_block: block) : @options) ) 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.
64 65 66 67 |
# File 'lib/wrest/multipart.rb', line 64 def put_multipart(parameters = {}, headers = {}, &block) Http::PutMultipart.new(self, parameters, headers, block ? @options.merge(callback_block: block) : @options).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.
74 75 76 77 78 |
# File 'lib/wrest/multipart.rb', line 74 def put_multipart_async(parameters = {}, headers = {}, &block) request = Http::PutMultipart.new(self, parameters, headers, block ? @options.merge(callback_block: block) : @options) (@options[:asynchronous_backend] || Wrest::AsyncRequest.default_backend).execute(request) end |