ItsNatTimer timer = clientDoc.createItsNatTimer();
EventListener timerListener = new EventListener() {
public void handleEvent(Event evt) { } // Nothing to do, this timer just update the client with the current state of progressElem
};
this.currentTimerHnd = timer.schedule(null,timerListener,0,1000);
final ItsNatTimerHandle timerHnd = currentTimerHnd;
if (currentIframeUpload != null) currentIframeUpload.dispose();
this.currentIframeUpload = iframe.getHTMLIFrameFileUpload(clientDoc,input.getHTMLInputElement());
final HTMLIFrameFileUpload iframeUpload = currentIframeUpload;
ItsNatServletRequestListener listener = new ItsNatServletRequestListener()
{
public void processRequest(ItsNatServletRequest request, ItsNatServletResponse response)
{
FileUploadRequest fileUpReq = iframeUpload.processFileUploadRequest(request, response);
try
{
ServletResponse servRes = response.getServletResponse();
Writer out = servRes.getWriter();
out.write("<html><head /><body>");
out.write("<p>Content Type: \"" + fileUpReq.getContentType() + "\"</p>");
out.write("<p>Field Name: \"" + fileUpReq.getFieldName() + "\"</p>");
out.write("<p>File Name: \"" + fileUpReq.getFileName() + "\"</p>");
out.write("<p>File Size: " + fileUpReq.getFileSize() + "</p>");
if (fileUpReq.getFileSize() > 4*1024*1024)
out.write("<h2>TOO LARGE FILE</h2>");
out.write("</body></html>");
long fileSize = fileUpReq.getFileSize();
if ((fileSize == 0)||(fileSize > 4*1024*1024)) return;
byte[] buffer = new byte[10*1024];
InputStream fileUp = fileUpReq.getFileUploadInputStream();
long count = 0;
int read = 0;
do
{
if (iframeUpload.isDisposed())
return;
try { Thread.sleep(50); }catch(InterruptedException ex){ }
count += read;
updateProgression((count * 100) / fileSize);
read = fileUp.read(buffer);
}
while (read != -1);
}
catch(IOException ex)
{
throw new RuntimeException(ex);
}
finally
{
ItsNatDocument itsNatDoc = getItsNatDocument();
synchronized(itsNatDoc)
{
timerHnd.cancel();
}
}
}
};
iframeUpload.addItsNatServletRequestListener(listener);