7

hi I have seen httparty but I don't have a idea to how to implement there are many example of model file but which paramater can be use for upload the video file

hardik9045
  • 499
  • 1
  • 6
  • 17
  • 1
    Have you looked at the [httparty examples](https://github.com/jnunemaker/httparty/tree/master/examples) in the httparty repo? – idlefingers Feb 28 '11 at 13:21

4 Answers4

6

HTTMultiParty supports file uploads by posting a multipart MIME document. It wraps HTTParty so you use it in the same way. For the file, just supply a File object. Example from the README:

require 'httmultiparty'
class SomeClient
  include HTTMultiParty
  base_uri 'http://localhost:3000'
end

response = SomeClient.post('/', :query => {
  :foo      => 'bar',
  :somefile => File.new('README.md')
})
Mark Thomas
  • 37,131
  • 11
  • 74
  • 101
1

By using the RestClient gem we can easily handle the file uploads, but make sure that you install the rest-client gem.

And I have also attached screen shot of example request from postman.

And the code in controller as like below,

  res = RestClient::Request.execute(
      method: :post,
      url: "http://www.your_url.com",
      payload: params,

      headers: {
          'Content-Type' => "multipart/form-data",
          Authorization: "some_key",
          :Accept => "*/*"
      }

  )

enter image description here

Naveen Thonpunoori
  • 814
  • 11
  • 19
1

HTTParty does not appear to support file uploads (as least as of 2009):

Google groups where some people say it's not supported: http://groups.google.com/group/httparty-gem/browse_thread/thread/fe8a3af8c46e7c75

Open Issue concerning it: https://github.com/jnunemaker/httparty/issues/77

Fishtoaster
  • 1,809
  • 2
  • 20
  • 36
0

Here is the multipart example from HTTParty:

# If you are uploading file in params, multipart will used as content-type automatically

HTTParty.post(
  'http://localhost:3000/user',
  body: {
    name: 'Foo Bar',
    email: 'example@email.com',
    avatar: File.open('/full/path/to/avatar.jpg')
  }
)

Now, you can access the uploaded file in the controller as follows:

uploaded_io = params[:avatar]
File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'wb') do |file|
  file.write(uploaded_io.read)
end 
Rajkaran Mishra
  • 4,532
  • 2
  • 36
  • 61