Accessing checksum of files in tmp folder

Enhanced frontend add-on to queue files.
Post Reply
meenakshi
Posts: 5
Joined: Tue Sep 15, 2009 1:02 pm

Accessing checksum of files in tmp folder

Post by meenakshi »

Hello again,

Thanks for answering my previous questions.

I am still using the unregistered version of JBatchUpload to make it work with our system. I am at the final stage and we have one more issue.

I am using the JSPUpload's process.jsp code and I created two directories:
<% String directory = "C:/UploadedFiles/jfileupload"; %>
<% String tmpdirectory = "C:/UploadedFiles/jfileupload/tmp"; %>

To set temporary files in the tmp folder, I write
upBean.setParsertmpdir(tmpdirectory + account);

Now my task is that I need to calculate the checksum of
1) the file which is being uploaded [this is accessed from the request ]
2) the file which lies in the tmp folder [ the filename.tmp file which is created in tmp folder]

Then I am suppose to compare both of them to see if the file which is being uploaded and the file which lies in the tmp folder has the same checksum.

Is it really possible to do something like this? Could you please provide me with some suggestion?

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: Accessing checksum of files in tmp folder

Post by support »

Well, yes. And this feature is almost available in process.jsp and in JFileUpload.
Did you try:
<PARAM NAME="resume" VALUE="md5">
process.jsp will compute MD5 and send it back to applet before resuming.

meenakshi
Posts: 5
Joined: Tue Sep 15, 2009 1:02 pm

Re: Accessing checksum of files in tmp folder

Post by meenakshi »

Hello again,
My javascript code looks like below:

Code: Select all

<!--
var _info = navigator.userAgent;
var _ns = false;
var _ns6 = false;
var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0);
if (_info.indexOf("Opera") > 0) _ie = false;
var _ns = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0) || (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0) || (_info.indexOf("AIX") > 0) || (_info.indexOf("OS/2") > 0) || (_info.indexOf("IRIX") > 0)));
var _ns6 = ((_ns == true) && (_info.indexOf("Mozilla/5") >= 0));
if (_ie == true) {
  document.writeln('<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH="430" HEIGHT="300" NAME="fileupload" codebase="http://java.sun.com/update/1.4.2/jinstall-1_4-windows-i586.cab#Version=1,4,0,0">');
}
else if (_ns == true && _ns6 == false) { 
  // BEGIN: Update parameters below for NETSCAPE 3.x and 4.x support.
  document.write('<EMBED ');
  document.write('type="application/x-java-applet;version=1.4" ');
  document.write('CODE="jfileupload.upload.client.MApplet.class" ');
  document.write('JAVA_CODEBASE="./" ');
  document.write('ARCHIVE="http://localhost:8080/jfiles/lib/jfileupload.jar,http://localhost:8080/jfiles/lib/httpimpl.jar,http://localhost:8080/jfiles/lib/chttpclient.jar,http://localhost:8080/jfiles/lib/clogging.jar,http://localhost:8080/jfiles/lib/batchui.jar" ');
  document.write('NAME="fileupload" ');
  document.write('WIDTH="430" ');
  document.write('HEIGHT="300" ');
  document.write('url="http://localhost:8080/jfiles/checkin_upload.jsp" ');
  document.write('paramfile="uploadfile" '); 
  document.write('authentication="auto"');
  document.write('param1="todo" ');
  document.write('value1="upload" '); 
  document.write('param2="relativefilename" ');
  document.write('value2="true" ');  
  document.write('resume=md5');  
  document.write('checksum="md5" ');
  document.write('post="http://localhost:8080/jfiles/success.jsp" ');  
  document.write('transferui="jfileupload.transfer.client.edesign.BatchTransferUI" ');  
  document.write('transferuiresources="i18n_pane" ');
  document.write('resources="i18n_bar" ');
  document.write('resetprogressbar="true" ');   
  document.write('mode="http" ');
  document.write('scriptable=true ');
  document.writeln('pluginspage="http://java.sun.com/products/plugin/index.html#download"><NOEMBED>');
  // END
}
else {
  document.writeln('<APPLET CODE="jfileupload.upload.client.MApplet.class" JAVA_CODEBASE="./" ARCHIVE="http://localhost:8080/jfiles/lib/jfileupload.jar,http://localhost:8080/jfiles/lib/httpimpl.jar,http://localhost:8080/jfiles/lib/chttpclient.jar,http://localhost:8080/jfiles/lib/clogging.jar,http://localhost:8080/jfiles/lib/batchui.jar" WIDTH="430" HEIGHT="300" NAME="fileupload">');
}
// BEGIN: Update parameters below for INTERNET EXPLORER, FIREFOX, SAFARI, OPERA, MOZILLA, NETSCAPE 6+ support.
document.writeln('<PARAM NAME=CODE VALUE="jfileupload.upload.client.MApplet.class">');
document.writeln('<PARAM NAME=CODEBASE VALUE="./">');
document.writeln('<PARAM NAME=ARCHIVE VALUE="http://localhost:8080/jfiles/lib/jfileupload.jar,http://localhost:8080/jfiles/lib/httpimpl.jar,http://localhost:8080/jfiles/lib/chttpclient.jar,http://localhost:8080/jfiles/lib/clogging.jar,http://localhost:8080/jfiles/lib/batchui.jar">');
document.writeln('<PARAM NAME=NAME VALUE="fileupload">');
document.writeln('<PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">');
document.writeln('<PARAM NAME="scriptable" VALUE="true">');
document.writeln('<PARAM NAME="url" VALUE="http://localhost:8080/jfiles/checkin_upload.jsp">');
document.writeln('<PARAM NAME="paramfile" VALUE="uploadfile">');
document.writeln('<PARAM NAME="authentication" VALUE="auto">');
document.writeln('<PARAM NAME="param1" VALUE="todo">');
document.writeln('<PARAM NAME="value1" VALUE="upload">');
document.writeln('<PARAM NAME="param2" VALUE="relativefilename">');
document.writeln('<PARAM NAME="value2" VALUE="true">');
document.writeln('<PARAM NAME="resume" VALUE="md5">');
document.writeln('<PARAM NAME="checksum" VALUE="md5">');
document.writeln('<PARAM NAME="post" VALUE="http://localhost:8080/jfiles/success.jsp">');
document.writeln('<PARAM NAME="transferui" VALUE="jfileupload.transfer.client.edesign.BatchTransferUI">');
document.writeln('<PARAM NAME="transferuiresources" VALUE="i18n_pane">');
document.writeln('<PARAM NAME="resources" VALUE="i18n_bar">');
document.writeln('<PARAM NAME="resetprogressbar" VALUE="true">');
document.writeln('<PARAM NAME="mode" VALUE="http">');
// END
if (_ie == true) {
  document.writeln('</OBJECT>');
}
else if (_ns == true && _ns6 == false) {
  document.writeln('</NOEMBED></EMBED>');
}
else {
  document.writeln('</APPLET>');
}
//-->
In the checkin_upload.jsp page, my code is looks somewhat like:

Code: Select all

    Logger logger = Logger.getLogger("checkin_upload.jsp");              
                 
	if (MultipartFormDataRequest.isMultipartFormData(request))
		{
			// Parse multipart HTTP POST request.
			MultipartFormDataRequest mrequest = null;
			try
			{
				mrequest = new MultipartFormDataRequest(request, null, -1, MultipartFormDataRequest.CFUPARSER, encoding, allowresume);
			} 
			catch (Exception e)
			{
				// Cancel current upload (e.g. Stop transfer)
				// Only if allowresume = false
			}
			String todo = null;
			logger.info("----------------------");
			logger.info("resume => "+request.getHeader("resume"));
I am using the process.jsp code of JSPUpload but I was trying to check if the resume param works properly or not. When I run the above code, I get null. Am I accessing it properly? or have I declared the resume param properly? I am testing my changes in IE 6.

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: Accessing checksum of files in tmp folder

Post by support »

There are 2 requests issued by applet for resume:
- HTTP HEAD with 'resume' header which contains "md5" or "crc"
The JSP must return the MD5 computed for file on server-side
- HTTP POST for upload without 'resume' header.

But I understand that you want the applet to compute MD5 and send it in the upload request, correct? So you don't need resume parameter but checksum parameter as you did:
<PARAM NAME="checksum" VALUE="md5">

then in you JSP:
request.getHeader("checksum") will return the MD5 value such as 3fefd95937071577d6fb7e5e2c8205f6

Does it work for you?

meenakshi
Posts: 5
Joined: Tue Sep 15, 2009 1:02 pm

Re: Accessing checksum of files in tmp folder

Post by meenakshi »

Hello again,

Yes this was what I was doing it. So it seems to be the right procedure.

I had one more question, I need to forward this checksum to current / another page. So I define
document.writeln('<PARAM NAME="post" VALUE="http://localhost:8080/jfileupload/success.jsp">');
document.writeln('<PARAM NAME="postparameters" VALUE="extra">');

What I understand, by saying postparameters is extra, I can get the extra parameters. In the success.jsp page, i can see
logger.info("file "+request.getParameter("filename1"));
which returns me the file name. I was wondering if I can get the checksum also. [Since I define postparameter as extra]

As you can see, I have already defined checksum in my javascript file.

Thanks for your prompt support.

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: Accessing checksum of files in tmp folder

Post by support »

No, checkum is not passed in "post" or "forward" parameters. If you need this feature then we can implement this feature. Contact support(at)jfileupload(dot)com

Post Reply