views:

156

answers:

2

I'm writing GWT application where I need to upload video file and encode that video into different video formats. I've decided to use Panda Video Converter. I was able to run panda on my EC2 instance (using their image) and I can upload video from Panda's test pages but now I'm trying to make same thing with my own application in GWT. The question that I have is: How do I get Video id and how do I post my video to the server. What URL do I need to use for that? I tried to read their documentation but have no clue where to start. This is my fist time working with webservices and url, probably that's why I don't how it works.

+1  A: 

Disclaimer: I have no idea how the Panda Video Converter works, this is just an example of using RequestBuilder to make GET and POST requests to a server.

The steps to accomplish this seem to be roughly:

  1. Send a POST to hq.pandastream.com/videos.(yaml|xml) with your account ID as a parameter.
  2. Receive a response including the ID of the new video you've created (a placeholder)
  3. Display a form to the user based on the ID. The form is retrieved by sending a GET to upload.pandastream.com/videos/[id]/form
  4. Submitting this form uploads the video, whose information can be retrieved by sending a GET to GET hq.pandastream.com/videos/id.(yaml|xml)

Since the only elements of this process are POST and GET requests, you can use the RequestBuilder to make these requests for you in GWT.

We'll go through step by step.

Send a POST to hq.pandastream.com/videos.xml with your account ID as a parameter.

RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "http://hq.pandastream.com/videos.xml");
rb.sendRequest("account_key=foo", new RequestCallback() {
  protected void onResponseReceived(Request request, Response, response) {
    // parse XML to get "id" element
  }
  // onError() ...
});

Now that you have the ID, you can make another request to get the upload form HTML.

rb = new RequestBuilder(RequestBuilder.GET, "http://upload.pandastream.com/videos/" + id + "/form");
rb.sendRequest(null, new RequestCallback() {
  protected void onResponseReceived(Request request, Response, response) {
     // this may not work, and it may be a bad idea to inject third-party HTML
     // straight into your page. You might also want to open a popup window
     // instead of injecting the HTML directly.
    someWidget.setHTML(response.getText());
  }
  // onError() ...
});

With that form, the user uploads the video, etc.

Now, to get info about the video, it's -- you guessed it -- another RequestBuilder call.

rb = new RequestBuilder(RequestBuilder.GET, "http://hq.pandastream.com/videos/" + id + ".xml");
rb.sendRequest(null, new RequestCallback() {
  protected void onResponseReceived(Request request, Response, response) {
    // parse response XML to get info you want
  }
  // onError() ...
});

Another disclaimer: This is a very rough outline of what appears to be the process of uploading a video, based on the docs you linked. This just serves as a basic example of using RequestBuilder to make GET/POST calls.

Jason Hall
For some reason it redirects me to login page. Here is what I see in the log: ~ Started request handling: Wed Mar 17 00:38:11 +0000 2010 ~ Params: {"format"=>nil, "action"=>"create", "controller"=>"videos"} ~ Redirecting to: /login (302) ~ {:dispatch_time=>0.00055, :after_filters_time=>6.0e-06, :action_time=>0.000226} Any idea?
Maksim
Are you sure you authenticated first by passing your account key? And are you using the id that the server returns in your consequent calls?
Igor Klimer
Which step redirects you to a login page? Are you replacing "foo" with your account key instead of "account_key=foo" ?
Jason Hall
yes I did replayed 'foo' with my secret key (api_key) that i set in panda_init.rb file... It looks like now I'm getting 406 error... what could it mean? may be that's XSS security?
Maksim
+1  A: 

Hi Maksim,

I just wanted to see if you had worked this out. If you need some more help with the open source version feel free to ask on the Google Groups list we have: http://groups.google.com/group/pandastream

You might also be interested in trying out the hosted version we launched publicly last week: http://pandastream.com/

dctanner