Good afternoon: I need to transfer an audio file (. Wav) from client to server. The problem is that my code runs without errors but the file is not transferred as in the destination folder does not appear! I hope someone can help me .. Greetings!
Código:
try {
URL pagina = new URL("http://localhost:8081/prueba/audio.wav");
HttpURLConnection con = (HttpURLConnection) pagina.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestMethod("POST");
con.setRequestProperty("content-type", "audio/x-wav");
con.setUseCaches(false);
con.connect();
String filename = System.getProperty("user.home") + "\\.vmaudio\\" + "audio.wav";
FileInputStream is = new FileInputStream(filename);
DataOutputStream fos = new DataOutputStream(con.getOutputStream ());
int fByte;
int bytesTrasferidos = 0;
while ((fByte = is.read()) != -1) {
fos.write(fByte);
fos.flush();
bytesTrasferidos++;
}
System.out.println("Bytes Transferidos: "+bytesTrasferidos);
fos.close();
is.close();
con.disconnect();
} catch (MalformedURLException ex) {
Logger.getLogger(pruebasVarias.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(pruebasVarias.class.getName()).log(Level.SEVERE, null, ex);
}
PD: may need to create a servlet that receives the file and them copy to the folder on the server but the truth is not, my idea was to send it directly from the client ..