1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
public void uploadVideo(){
try {
File myVideo = new File("/home/maVideo.MOV");
System.out.println("Transfert d'un fichier de : " +myVideo.length() + " octets.");
PostMethod filePost = new PostMethod("http://www.pageVideo.com/add");
// new StringPart("param_name", "value"),new FilePart("data", f)
Part[] parts={ new FilePart("data", myVideo) };
filePost.setRequestEntity( new MultipartRequestEntity(parts, filePost.getParams()) );
HttpClient client = new HttpClient();
int status = client.executeMethod(filePost);
System.out.println(status); // est égale a 500
} catch (FileNotFoundException e){
e.printStackTrace();
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} |
Partager