• Zach Cowan 2 months ago
    I edited the post as it looks like the code got garbled during posting, this should be right now.

    I am trying to implement upload via the API in Ruby using the net/http lib. I dont seem to be getting anywhere so I am hoping somebody can offer some assistance to help me figure out where the hurdle is.

    Here is the code I have, at the point that this runs I already have logged-in to the website as the user (which has granted athorization to the application), have an auth_token and a ticket_id for the upload.


    host = 'www.vimeo.com'
    upload_path = '/services/upload'

    upload_base_sig = "#{@secret}api_key#{@api_key}ticket_id#{ticket}"
    upload_api_sig = Digest::MD5.hexdigest( upload_base_sig )


    # Create the POST data, multipart/form format
    data = <<"DATA"
    --vimeo_upload
    Content-Disposition: form-data; name="api_key"
    #{@api_key}
    --vimeo_upload
    Content-Disposition: form-data; name="auth_token"
    #{token}
    --vimeo_upload
    Content-Disposition: form-data; name="api_sig"
    #{upload_api_sig}
    --vimeo_upload
    Content-Disposition: form-data; name="ticket_id"
    #{ticket}
    --vimeo_upload
    Content-Disposition: form-data; name="video"; filename="zach.mpg"
    Content-Transfer-Encoding: binary
    Content-Type: video/mpg

    #{video}
    --vimeo_upload--
    DATA

    headers = {
    'Accept' => 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, application/x-gsarcade-launch, */*',
    'Accept-Language' => 'en-us',
    'Host' => 'www.vimeo.com',
    'Referer' => "http://www.vimeo.com/",
    'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)',
    'Content-Type' => 'multipart/form-data; boundary="vimeo_upload"',
    'Accept-Encoding' => 'gzip, deflate',
    'Content-Length' => data.length.to_s,
    'Connection' => 'Keep-Alive',
    'Cache-Control' => 'no-cache',
    'Cookie' => cookies
    }

    http = Net::HTTP.new( host )
    resp, data = http.post( upload_path , data, headers )

    puts 'Code: ' resp.code
    puts 'Message: ' resp.message
    puts 'Data: '
    puts data

    # It returns code 200 and the message is Ok, but the data passed back doesn't look right, it looks like the binary video content, or at least a chunk of it. I think the problem is in the post data code, but not certain...

    Am hoping someone spots a problem for me to address.

    Thanks,
    Andy
  • Ted Roden 2 months ago
    Hrm. I don't know enough ruby to figure this out by looking at it...

    I'll try to replicate it with the code, but if anyone who knows ruby would like to step in... HELP US!
  •  
This conversation is missing your voice. Take five seconds to join Vimeo or log in.
Need help with Vimeo?
Please check the Help page for general FAQ, video tutorials, and other helpful information
up down
Topic Browser
API 102

Sponsored by: