Using Sinatra with Webhook to retrieve the url of one file upload

  • jdelgado
    Asked on November 19, 2015 at 11:40 AM

    I am trying to obtain the url direction of a file (uploaded) located in jotform. I use Sinatra in the Backend to control the /POST for jotform, the webhook is already working and i receive the response from jotform.

    The response has a format that i can not parse in ruby using JSON.parse(body.request.read). I think it happens because of the format used in that object. So i want to know what is the format of that object to parse into an json object and retrieve the url with the location of the file.

    Example of the request.body.read without the parsing:

    $ rackup -p 8080 launch_server.rb 

    [2015-11-19 11:52:24] INFO  WEBrick 1.3.1

    [2015-11-19 11:52:24] INFO  ruby 2.1.2 (2014-05-08) [x86_64-linux-gnu]

    == Sinatra (v1.4.6) has taken the stage on 4567 for development with backup from WEBrick

    [2015-11-19 11:52:24] INFO  WEBrick::HTTPServer#start: pid=9081 port=4567

    ------------------------------b1fc756b0d39

    Content-Disposition: form-data; name="formID"

     

    53165035132647

    ------------------------------b1fc756b0d39

    Content-Disposition: form-data; name="submissionID"

     

    323759367249625573

    ------------------------------b1fc756b0d39

    Content-Disposition: form-data; name="webhookURL"

     

    https://7fc02965.ngrok.io/webhook/heywatch

    ------------------------------b1fc756b0d39

    Content-Disposition: form-data; name="ip"

     

    186.94.219.42

    ------------------------------b1fc756b0d39

    Content-Disposition: form-data; name="formTitle"

     

    Upload Files

    ------------------------------b1fc756b0d39

    Content-Disposition: form-data; name="pretty"

     

    Full Name: , E-mail:, Order :, ID:28, Upload your Prescription:Screenshot from 2015-09-19 08:58:09.png

    ------------------------------b1fc756b0d39

    Content-Disposition: form-data; name="username"

     

    username

    ------------------------------b1fc756b0d39

    Content-Disposition: form-data; name="rawRequest"

     

    {"slug":"submit\/53165035132647\/","q5_fullName5":{"first":"","last":""},"q7_email7":"","q8_order8":"","q10_id":28,"preview":"true","event_id":"1447950157883_53165035132647_fnvutIt","q1_uploadYour":["http:\/\/www.jotformz.com\/uploads\/jdelgado\/53165035132647\/323759367249625573\/Screenshot from 2015-09-19 08_58_09.png"]}

    ------------------------------b1fc756b0d39

    Content-Disposition: form-data; name="type"

     

    WEB

    ------------------------------b1fc756b0d39--

    localhost - - [19/Nov/2015:11:52:50 VET] "POST /webhook/heywatch HTTP/1.1" 200 0

    - -> /webhook/heywatch

     

    Thanks beforehand!

  • victor
    Replied on November 19, 2015 at 1:01 PM

    I'm sorry but not truly familiar with Sinatra and webhook. I was able to locate a small sample on the web on how to send and receive request through POST:

    https://github.com/sinatra/sinatra/blob/master/examples/chat.rb

    To get the URL of any upload file, you can use the following code sample

    $url = "http://www.jotform.com/uploads/Account_Username/".$formid."/".$submission_id."/".$upload;

    Please let us know if this helps.