Reputation: 2489
I am developing a functionality in liferay 6.1.1 where I need to upload videos to a vimeo account.
I have gone through vimeo's site (http://developer.vimeo.com/) to get its API. But didn't get any API to make download and use. Can anybody guide me how I can use this API to upload videos on any vimeos's account?
Upvotes: 0
Views: 2440
Reputation: 2416
As documented on the Vimeo API page you need to send out a series of HTTP requests to their server. The easiest way to upload a file is to use Apache's HttpClient library.
In step 3 you actually do the upload, and how it is done you can see on this page. It basically boils down to this:
NOTE: This code is only a general idea, it is untested and will most likely not compile.
/**
* Uploads a file to Vimeo server.
* @returns null if successful, error line otherwise.
*/
public String uploadVideoFile(String vimeoUrl, String ticketId, File file) throws Exception
{
HttpClient client = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(vimeoUrl);
try {
MultipartEntity multiPartEntity = new MultipartEntity();
multiPartEntity.addPart("ticket_id", new StringBody(ticketId));
multiPartEntity.addPart("chunk_id", new StringBody("0"));
FileBody fileBody = new FileBody(file, "application/octect-stream");
multiPartEntity.addPart("file_data", fileBody);
postRequest.setEntity(multiPartEntity);
HttpResponse response = client.execute(postRequest);
if (response != null && response.getStatusLine().getStatusCode() != 200) {
return response.getStatusLine();
}
}
catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
Call it like this:
String status = uploadVideoFile("http://1.2.3.4/upload_multi",
ticket, file);
You could also try using the streaming method as explained on the Vimeo page.
Upvotes: 1