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 and not when using libcurl. 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)

Instance Method Details

- (Object) post_multipart(parameters = {}, headers = {}, &block)

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 ? @options.merge(:callback_block => block) : @options).invoke
end

- (Object) post_multipart_async(parameters = {}, headers = {}, &block)

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
54
# File 'lib/wrest/multipart.rb', line 51

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))
  nil
end

- (Object) put_multipart(parameters = {}, headers = {}, &block)

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.



58
59
60
# File 'lib/wrest/multipart.rb', line 58

def put_multipart(parameters = {}, headers = {}, &block)
  Http::PutMultipart.new(self, parameters, headers, block ? @options.merge(:callback_block => block) : @options).invoke
end

- (Object) put_multipart_async(parameters = {}, headers = {}, &block)

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.



67
68
69
70
# File 'lib/wrest/multipart.rb', line 67

def put_multipart_async(parameters = {}, headers = {}, &block)
  (@options[:asynchronous_backend] || Wrest::AsyncRequest.default_backend).execute(Http::PutMultipart.new(self, parameters, headers, block ? @options.merge(:callback_block => block) : @options))
  nil
end