1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
File result=new File("tmp/updatefiles"+ "/" + nom+s+Random+"."+extension);
Socket so=new Socket("127.0.0.1",8080);
String path = "http://127.0.0.1/uploadfiles";
this.selectedFileName=nom+s+Random+"."+extension;
try {
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(so.getOutputStream(), "UTF8"));
wr.write("POST " + path + " HTTP/1.0\r\n");
wr.write("Host: http://127.0.0.1\r\n");
wr.write("Content-Length: " + event.getFile().getSize() + "\r\n");
wr.write("Content-Type: application/x-www-form-urlencoded\r\n");
wr.write("\r\n");
wr.write(event.getFile().getContents().toString());
wr.flush();
FacesMessage msg = new FacesMessage("Succesful",
event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
} catch (IOException e) {
e.printStackTrace();
FacesMessage error = new FacesMessage("The files were not uploaded!");
FacesContext.getCurrentInstance().addMessage(null, error);
} |
Partager