Upload Video file using HttpClient-Collection of common programming errors
I’m building Java client that will automatically upload file from Java server to Panda Instance that I installed on my EC2 cloud using their AMI. I’m trying to use Apache HTTP Components to upload to Panda Server (Panda Stream). It works fine with my browser client but for some reason I can’t upload from that library. Here is my code:
String videoUploadUrl = "http://[panda server ip]/videos/" + getVideoID() + "/upload.xml";
File file = new File("/temp/videofile.mp4");
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost(videoUploadUrl);
MultipartEntity mpEntity = new MultipartEntity();
ContentBody fBody = new FileBody(file);
mpEntity.addPart("userfile", fBody);
httppost.setEntity(mpEntity);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response2 = httpclient.execute(httppost); //