Rails: open-uri, pdf to api post, timeout -


i'm trying upload document drchrono via api. web browser when go url specified , using devise security (authenticate_user!) downloads in 68ms. when run below code timeout error. pdf file 1 page , made using prawn.

  open('http://' + host + '/recording/' + recording.id.to_s + '/analysis.pdf') |file|     params = {       'document' => file.read,       'doctor' => 'https://drchrono.com/api/doctors/' + doctor.id,       'patient' => 'https://drchrono.com/api/patients/' + recording.patient.chrono_id.to_s,       'description' => 'report',       'date' => time.now.strftime("%y/%m/%d").gsub('/', '-')     }     response = httparty.post('https://drchrono.com/api/documents', :headers => headers, :body => params)     data = json.parse(response.body)   end 

my log shows right after timeout

started "/recording/131/analysis.pdf" ip @ 2014-05-29 10:18:43 -0700 processing dashboard::recordingscontroller#report pdf   parameters: {"id"=>"131"} completed 401 unauthorized in 8ms 

i thought because devise security wasn't passing correct parameters. so, switched on particular controller api security uses token authentication system. real change url after open included auth token.

however, still timeout error in exact same place followed by

started "/recording/132/analysis.pdf?token=relevant_token" ip @ 2014-05-29 10:27:52 -0700 processing dashboard::recordingscontroller#report pdf   parameters: {"token"=>relevant_token, "id"=>"132"}   user load (0.6ms)  select "users".* "users" (authentication_token = 'sqvyumxwsrsynxhn7pbj') order "users"."id" asc limit 1   recording load (1.0ms)  select "recordings".* "recordings" "recordings"."user_id" in (4)   note load (0.4ms)  select "notes".* "notes" "notes"."user_id" in (4)   accessiblepatient load (0.4ms)  select "accessible_patients".* "accessible_patients" "accessible_patients"."user_id" in (4)   patient load (0.7ms)  select "patients".* "patients" "patients"."id" in (93, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 114, 113)   recording load (0.5ms)  select "recordings".* "recordings" "recordings"."id" = $1 limit 1  [["id", "132"]]   patient load (0.3ms)  select "patients".* "patients" "patients"."id" in (97)   note load (1.7ms)  select "notes".* "notes" "notes"."patient_id" = $1  [["patient_id", 97]]   recording load (4.3ms)  select "recordings".* "recordings" "recordings"."patient_id" = $1  [["patient_id", 97]]   user load (0.4ms)  select "users".* "users" "users"."id" = $1 limit 1  [["id", 4]]   rendered text template (0.0ms) sent data  (6.4ms) completed 200 ok in 563ms (views: 6.2ms | activerecord: 10.4ms) 

this leads me believe initial timeout not connected lack of authorization else since when access not denied i'm still timing out.

i researched set-up , (open io stream local file or url) suggests i'm on right path.

since pdf file literally 1 page , takes mere 68s usually, don't see why i'd having issues timeout. ideas?

edit:

this person seems have had similar issue (rails open-uri breaking on path) suggested solution i'm doing (thin instead of default server).

edit:

let's more specific. works.

  content = open('http://www.google.com').read 

these not.

  content = open('http://localhost:3000').read   content = open('http://' + host).read 

i have puma server running faye , thin server running via rails s.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -