0

I am new to Rails and Context.IO. I am trying to create a record in my database based on values fetched from mail.

I am trying to fetch mail attachment and download that onto a directory in my /public on my server using contextio.

I have successfully got the path of the attachment, the only problem is when i am trying to download, i am getting stuck.

I have tried 1. "net/http", this is unsuccessful coz the URI is https. 2. FileUtils.cp_r(source,destination), It says No such file or directory for my source. If i access the source uri from browser it pops up me to download the file.

Nikunj Thakkar
  • 351
  • 1
  • 4
  • 8

1 Answers1

0

I don't don't know context.io, but I took a look at the api quickly and found this to download an attachment: http://context.io/docs/2.0/accounts/files/content

Thus, to download the attachment, just try something like this in plain ruby:

require 'net/http'
account_id = 12345
file_id = 45678

Net::HTTP.start("https://api.context.io") do |http|
    resp = http.get("/2.0/accounts/#{account_id}/files/#{file_id}/content")
    open("attachment.extension", "wb") do |file|
        file.write(resp.body)
    end
end
Arkan
  • 6,196
  • 3
  • 38
  • 54