|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Aug 2004
Messaggi: 83
|
[JAVA] multipart/form-data invio dati parziali
Invio in java la mia form, invece che farla in html, di tipo multipart/form-data.
una pagina php che riceve la form deve poter salvare il file che gli arriva. mi fornisce un errore del tipo 3, cioè partial upload. allora ho creato una servlet di verifica per controllare cosa mi arriva lato server. le informazioni che mi arrivano sembrano tutte, ma quando la servlet salva l'array di byte non è l'immagine originale, quindi il php ha ragione. il pezzo di codice per l'invio della form è molto semplice i nomi delle variabili sono parlanti DataInputStream fis = new DataInputStream(new BufferedInputStream(new FileInputStream(theFile))); byte[] theData = new byte[(int) theFile.length()]; DataOutputStream raw = new DataOutputStream(socket.getOutputStream()); Writer wr = new OutputStreamWriter(raw); String trail = "\r\n---------------------------115756643718031969371809661030\r\n"; String command = "-----------------------------115756643718031969371809661030\r\n" + "Content-Disposition: form-data; name=\"userfile\"; filename=\"" + fileName + "\"\r\n" + "Content-Type: image/jpg\r\n" + "\r\n"; String header = "POST " + path + " HTTP/1.0\r\n" + "Content-Type: multipart/form-data; boundary=---------------------------115756643718031969371809661030\r\n" + "Host: " + hostname + "\r\n" + "Content-Length: " + ((int) command.length() + theFile.length()+ trail.length() ) + "\r\n" + "\r\n"; wr.write(header); wr.write(command); wr.flush(); aw.write(theData); raw.flush( ); wr.write("\r\n---------------------------115756643718031969371809661030\r\n"); wr.flush(); dov'è il problema allora? grazie
__________________
SoftOXY!2004 |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 00:32.


















