Search code examples
ruby-on-railscurlcarrierwavehttpartyfog

HTTParty: Upload files


How would I do the following curl call using HTTParty?

$ curl -u andrew.lunny@nitobi.com -F keystore=@android.keystore -F 'data={"title":"Android Key","alias":"release", "key_pw":"90123456","keystore_pw":"78901234"}' https://build.phonegap.com/api/v1/keys/android

Here is what I currently have:

HTTParty.post("https://build.phonegap.com/api/v1/keys/android?auth_token=#{phonegap_token}", query: { keystore: file }, body: { data: {
    title: 'Android Key',
    alias: '...',
    key_pw: '...',
    keystore_pw: '...'
} }, format: :plain)

file is a Tempfile object which I fetched from the cloud storage where the file is located.

I want to pass a file which has been uploaded using Carrierwave and stored using Fog. Do I have to fetch it first from the URL?


Solution

  • I am not sure if it is going to work however you can try:

    HTTParty.post("https://build.phonegap.com/api/v1/keys/android",  
      body: { 
        data: {
          title: 'Android Key',
          alias: '...',
          key_pw: '...',
          keystore_pw: '...'
        }.to_json,
      keystore: File.read(file)
      })