client/server upload progress
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Roberto_Caniglia
Posted On:   Wednesday, November 27, 2002 08:16 AM

Hi I'm using the following partial code to upload data from a client to a server via HTTP. The data gets transferred as expected, however, I would like to show the data transfer progress on the client side. Is it possible to wait until each byte array (b in fout.write(b,0,len) below) has been completely transferred before writing another byte array to the HttpURLConnection stream (for now, all the data gets written to the stream quite quickly, and a long delay occures just before the "fout.close();" statement). Or, is there a better method of monitoring the data sent. Thanks, Roberto URL url = new UR   More>>


Hi



I'm using the following partial code to upload data from a client to a server via HTTP.



The data gets transferred as expected, however, I would like to show the data transfer progress on the client side.



Is it possible to wait until each byte array (b in fout.write(b,0,len) below) has been completely transferred before writing another byte array to the HttpURLConnection stream (for now, all the data gets written to the stream quite quickly, and a long delay occures just before the "fout.close();" statement).



Or, is there a better method of monitoring the data sent.



Thanks,

Roberto



URL url = new URL("http:// server_url /process.jsp");

HttpURLConnection conn = (HttpURLConnection)url.openConnection();



conn.setDoOutput(true);

conn.setUseCaches(false);

conn.setRequestProperty("Content-Length", ...



OutputStream fout = conn.getOutputStream();



FileInputStream fin = new FileInputStream( path );



byte [] b = new byte[1024];

int len = 0;

int count = 0;



while ( (len = fin.read(b)) != -1 ) {

count += len;

fout.write(b,0,len);



// Would like to wait until data has been sent to server before writing next byte array to fout



}



fin.close();

fout.flush();

fout.close();

   <<Less
About | Sitemap | Contact