House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Search cf-talk

July 04, 2009

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Home /  Groups /  ColdFusion Talk (CF-Talk)

uploading zip file with cfhttp creates file ColdFusion /java can't unzip but other apps can

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Daniel,
Jon Clausen
05/08/08 02:29 P
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Daniel Roberts
05/08/2008 10:57 AM

I'm running into a really frustrating problem. I am working on a monitoring tool for a batch email service we provide. The system accepts a zip file with required files, unzips them and then queues up the job for processing. I would like to be able to submit test jobs from a remote server on a regular basis. 1. I am updating and pulling together a few files on the fly into a zip file using CF. If I upload the file with <cfhttp> the file that lands on the server can not be unzipped by ColdFusion or a CFC that just makes java calls to unzip files. If I browse to the uploaded file on the server I can unzip it fine with WinRAR and Windows Explorer When I take the exact same zip file and submit it manually through our client web form, it is handled by CF without a problem. It appears that something subtle is changing with the file on upload. I'm not sure if there is some encoding i need to specify or what. I've looked at the docs and tried many variations on the code without any luck. The file is getting there but something is going on: <cfhttp url="#instance.jobIDSubmitURL#" method="post" result="jobSubmitResult">   <cfhttpparam name="JobFile" type="file" file="#arguments.jobFilePath#" mimetype="application/zip" /> </cfhttp>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Daniel Roberts
05/08/2008 11:32 AM

Here is a one page test for the problem. I've tried this on different computers with Windows and OSX. Below is very basic, though messy, example of the problem. It may end up being a bug in CF or something, or I may just be missing something about uploading binary files...but I've tried all the option I could find with no success. The code does the following 1. creates a text file 2. creates a zip file with the text file 3. tries to unzip the file to make sure it is fine 4. uploads the file (processed by a <cfelse> block at the bottom) 5. tries to unzip the file uploaded The error occurs in step 5. CF just can't unzip the uploaded file, but I can unzip it using other tools. ================ <cfif not structKeyExists(url,"upload")>   <!--- create zip file then try to unzip --->     <cffile action="write" file="#expandPath(".")#\temp.txt" output="test" />     <cfzip action="zip" file="#expandPath(".")#\temp.zip" source="#expandPath(".")#\temp.txt">          <cftry>       <cfdirectory action="create" directory="#expandPath(".")#\unzip1">       <cfdirectory action="create" directory="#expandPath(".")#\unzip2">       <cfcatch></cfcatch>     </cftry>          <!--- try unzip wihtout upload --->     <cfset error = false>     <cftry>       <cfzip action="unzip" file="#expandPath(".")#\temp.zip" destination="#expandPath(".")#\unzip1" />       <cfcatch type="application">         <cfset error = true>       </cfcatch>     </cftry>          <cfoutput>       <p>         Unzip of non-uploaded file succeeded? #(not error)#       </p>     </cfoutput>        <!--- upload file to CF page that will attempt to unzip file (see <cfelse> below) --->     <cfset error = false>     <cfhttp url="http://#cgi.http_host##cgi.script_name#?upload" method="post" result="jobSubmitResult" multipart="true">       <cfhttpparam name="enctype" type="header" value="multipart/form-data">       <cfhttpparam name="zipfile" type="file" file="#expandPath(".")#\temp.zip" mimetype="application/zip" />     </cfhttp>          <cfif jobSubmitResult.filecontent does not contain "success">       <cfset error = true>     </cfif>          <cfoutput>     <p>       Unzip of uploaded file succeeded? #(jobSubmitResult.filecontent contains "success")#     </p>     <hr>     <cfif error>       <div>         #jobSubmitResult.filecontent#       </div>     </cfif>     </cfoutput> <cfelse>         <!--- upload processing --->     <cfset error = false>     <cftry>       <cfdirectory action="create" directory="#expandPath(".")#\uploaded">       <cfcatch type="application"></cfcatch>     </cftry>          <cffile action="upload" destination="#expandPath(".")#\uploaded" filefield="zipfile" nameconflict="overwrite">      <!--- attempt to unzip --->     <cftry>       <cfzip action="unzip" file="#expandPath(".")#\uploaded\#cffile.ServerFile#" destination="#expandPath(".")#\unzip2">       <cfcatch type="application">         <cfset error = true>         <cfdump var="#cfcatch#">       </cfcatch>     </cftry>        <cfif not error>       success     </cfif>    </cfif>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Daniel Roberts
05/08/2008 02:01 PM

I noticed some issues running the exampe code in OSX due to the slash direction. I have adjusted that and cleanup the code a bit. I also removed some extra attributes that I had added in an attempt to get this working, but isn't actually included in the CF docs as being necessary. === <!--- get base directory, includes system specific slash at end ---> <cfset path = getDirectoryFromPath(getCurrentTemplatePath()) /> <cfif not structKeyExists(url,"upload")>   <!--- create zip file --->     <cffile action="write" file="#path#temp.txt" output="test" />     <cfzip action="zip" file="#path#temp.zip" source="#path#temp.txt">        <!--- try to unzip file --->     <cfset error1 = false />     <cftry>       <cfzip action="unzip" file="#path#temp.zip" destination="#path#" />       <cfcatch type="application">         <cfset error1 = true />       </cfcatch>     </cftry>   <!--- upload file to CF page that will attempt to unzip file (see <cfelse> below) --->     <cfhttp url="http://#cgi.http_host##cgi.script_name#?upload" method="post" result="jobSubmitResult">       <cfhttpparam name="zipfile" type="file" file="#path#temp.zip" />     </cfhttp>          <cfset error2 = trim(jobSubmitResult.filecontent) is not "successful unzip" />        <!--- output results of test --->     <cfoutput>       <p>         Unzip of non-uploaded file succeeded?         #!error1#       </p>       <p>         Unzip of uploaded file succeeded?         #!error2#       </p>       <hr>       <cfif error2>         <div>           #jobSubmitResult.filecontent#         </div>       </cfif>              <!--- output code at the end to verify changes during testing --->         <cffile action="read" file="#getCurrentTemplatePath()#" variable="thisFile" />         <hr>         <pre>#htmlEditFormat(thisFile)#</pre>     </cfoutput> <cfelse>   <!--- save uploaded file to current folder, with different name --->     <cffile action="upload" destination="#path#temp_uploaded.zip" filefield="zipfile" nameconflict="makeunique" />        <!--- attempt to unzip file --->     <cfset error = false />     <cftry>       <cfzip action="unzip" file="#path#temp_uploaded.zip" destination="#path#" />       <cfcatch type="application">         <cfdump var="#cfcatch#" />         <cfset error = true />       </cfcatch>     </cftry>          <cfif not error>       successful unzip     </cfif> </cfif>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Jon Clausen
05/08/2008 02:29 PM

Daniel, If I'm reading correctly, you're uploading to an OSX server?    You   might want to use mode="777" on your <cffile> tags for creation to   allow read/write/execute permissions on the file you have created.       You could be running into a permissions issue on the file that has   nothing to do with your code. What is the error message you are receiving on the dump of the cfcatch   for the <cfzip action="unzip"...  ?   That might help to narrow down   the problem a bit. HTH, Jon On May 8, 2008, at 2:00 PM, Daniel Roberts wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Daniel Roberts
05/08/2008 02:58 PM

I have tried this on 2 Windows severs running 2000 and 2003 if I'm remembering correctly, and my MacBook Pro running Leopard. Here is the error detail and message... Detail: Ensure that the file is a valid zip file and it is accessible. Cause : java.util.zip.ZipException: error in opening zip file Message: Exception encountered while reading the file /Applications/JRun4/servers/cfusion/cfusion-ear/cfusion-war/dan_workspace/Scratch/temp_uploaded.zip. I can copy and paste the path right from the error message into "Start > Run" on Windows and the zip file opens right up. I am going to submit this as a bug and/or to the doc comments if there is no solution by this weekend. NOTE: I just noticed that in my updated example code I used "nameconflict="makeunique"" when saving the uploaded file but then referenced the file with a hardcoded file name. Not an issue on the first run but change "makeunique" to "overwrite" to prevent a new filename being created on every test so it will unzip the correct file. ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Daniel Roberts
05/09/2008 03:33 PM

Solution found thanks to -==cfSearching==- (http://cfsearching.blogspot.com/) over at the adobe cf forums. He noticed that the size received by ColdFusion is 2b bigger than the original file. If however an additional <cfhttpparam> form field is added after the file field, it magically works. If you add the form field before the file it doesn't work. I'm submitting this bug to adobe and hopefully this thread will help others who run into the problem. I searched google yesterday to find more info on the problem and this thread on cf-talk was one of the top results.


<< Previous Thread Today's Threads Next Thread >>

Mailing Lists