Re: app-fileservices no files in Request?

Nathan Kontny <Nathan.Kontny-UgwZ4owrJFB8UrSeD/[email protected]>
Newsgroups gmane.comp.java.keel.user
Message-ID <[email protected]>
Stephen, 

So I see that the StrutsClientConnector is now instead creating instances of
the
BinaryWrapper in the request.  I changed the FileUploadModel to look for this
wrapper instead of the "file_data" key.  Attached is the patch if you are
interested.  

I also negated the logic of the file_type map, as wouldn't it be easier for
users to specify the files that should be allowed (jpg, png, etc.) than have to
specify every file that shouldn't be allowed?  For example, the patch now has
this: 

if(!filetype_map.contains(file_extension)){
   res.addError("fileType", "$wrongFileType|"+file_extension);
}

-Nate


Quoting Stephen Davidson <[email protected]>:

> Nathan Kontny wrote:
> > I am using the latest app-fileservices and pretty close to the latest of
> > everything else from CVS.  When I use the file.upload-example, I see that
> > inside the FileUploadModel during the example it doesn't find any
> "file_data"
> > request parameters.  ( from the code: if(oneKey.indexOf("_file_data_") >
> 0){ ).
> >  
> > 
> > I am just using the example just as it comes out of the box, with a jpg of
> 27KB.
> >  Is this app working for anyone else right now? 
> > 
> > -Nate
> > _______________________________________________
> > User mailing list
> > [email protected]
> > http://lists.keelframework.org/listinfo.cgi/user-keelframework.org
> > 
> Hi Nate.
> 
> Mike is currently reworking the build process to make overrides easier.
> 
> In the meantime, here is a (slightly modified) excerpt from an
> internal project README I had put together.  I was planning on posting
> this when I had a few minutes, but I am hoping that Mike's build changes
> will elimnate much of the headaches involved.
> The other alternative is to
> 1) go modify clnt-struts/conf/client/snippets/
>      struts-config.xml
>      struts-config1.xml
> 2) Delete the keel-build/install directory, as well as the
> unpacked keel-build/deploy/jakarta-tomcat-4.1.30 directory
> (note that the clean target does NOT cause the modified snippet
> files to be redeployed - will possibly be fixed in the current build
> overhaul?)
> 3) build with the "clean complete-install" targets.
> 
> Regards,
> Steve
> 
> <===Begin Readme===>
> After a completeinstall, the following change needs to be made;
> 	* The struts-config.xml file used in the webapp should be altered to add the
> <form-property> tag for
> 	each file input specified in the jsp page. This is to tell the
> org.apache.struts.action.DynaActionForm
> 	that the file type inputs should be mapped to
> org.apache.struts.upload.FormFile objects.
> 
> This change would be made to the	
>
keel-build/deploy/jakarta-tomcat-4.1.29/webapps/struts/WEB-INF/struts-config.xml
> 	
> <!-- ========== Form Bean Definitions ===================================
> -->
>    	<form-beans>
>      	<form-bean name="none" type="org.apache.struts.action.DynaActionForm">
> 			<form-property name="myFile1" type="org.apache.struts.upload.FormFile"/>
> 			<form-property name="myFile2" type="org.apache.struts.upload.FormFile"/>
> 		</form-bean>
>    	</form-beans>
> 
> <!-- ========== To Enable Svc-Fileupload-Struts as well =================
> -->
>    <!-- ========== Form Bean Definitions ===================================
> -->
>    <form-beans>
> 
>          <form-bean      name="none"
>                          type="org.apache.struts.action.DynaActionForm">
>              <form-property name="file1"
>                          type="org.apache.struts.upload.FormFile"/>
>              <form-property name="file2"
>                          type="org.apache.struts.upload.FormFile"/>
>              <form-property name="file3"
>                          type="org.apache.struts.upload.FormFile"/>
>              <form-property name="clipView"
> type="org.apache.struts.upload.FormFile"/>
>              <form-property name="clipFile"
> type="org.apache.struts.upload.FormFile"/>
>          </form-bean>
> 
>    </form-beans>
> 
> 
> -- 
> Java/J2EE Developer/Integrator
> Chair, Dallas/FortWorth J2EE Sig
> 214-724-7741
> 
> 
> _______________________________________________
> User mailing list
> [email protected]
> http://lists.keelframework.org/listinfo.cgi/user-keelframework.org
>
patch.txt (text/plain, 2.7 KB)
Index: FileUploadModel.java
===================================================================
RCS file: /cvsroot/keel/app-fileservices/src/java/org/keel/apps/fileservices/model/FileUploadModel.java,v
retrieving revision 1.1
diff -u -r1.1 FileUploadModel.java
--- FileUploadModel.java	12 Jan 2004 19:52:20 -0000	1.1
+++ FileUploadModel.java	29 Apr 2004 03:29:37 -0000
@@ -23,6 +23,7 @@
 
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.keel.comm.BinaryWrapper;
 import org.keel.services.model.Command;
 import org.keel.services.model.Input;
 import org.keel.services.model.ModelException;
@@ -206,13 +207,18 @@
         
         for(Iterator i=params.keySet().iterator();i.hasNext();){
 			String oneKey = (String)i.next();
+			Object oneEntry = params.get(oneKey);
             log.debug("\nCurrent key/value: " + oneKey + '/' + params.get(oneKey));
-
-			if(oneKey.indexOf("_file_data_") > 0){
+            
+            if(oneEntry instanceof BinaryWrapper){
+                
+                BinaryWrapper oneFile = (BinaryWrapper)oneEntry; 
+                
+			//if(oneKey.indexOf("_file_data_") > 0){
                 //Key = <fieldname> + "_file_data_" + filename
-                final int keyIdx = oneKey.indexOf("_file_data_");
-                final String fieldName = oneKey.substring(0, keyIdx);
-				final String file_name = oneKey.substring(keyIdx + 11);
+                //final int keyIdx = oneKey.indexOf("_file_data_");
+                final String fieldName = oneKey;//oneKey.substring(0, keyIdx);
+				final String file_name = oneFile.getName() ;//oneKey.substring(keyIdx + 11);
                 if (log.isDebugEnabled()){
                     log.debug("Field Name: " + fieldName);
                     log.debug("File Name: " + file_name);
@@ -221,7 +227,9 @@
 					
 					int lastDotIndex = file_name.lastIndexOf(".");
 					String file_extension = file_name.substring(lastDotIndex + 1);
-					if(filetype_map.contains(file_extension)){
+					
+					//If the fileType is not one that we have specified, we reject it
+					if(!filetype_map.contains(file_extension)){
 						res.addError(
 							"fileType",
 							"$wrongFileType|"+file_extension);
@@ -234,7 +242,8 @@
 					}
 				} //end if (filetype_map)
                 //BUG: This loads all of the file into memory.  See bug #819550
-				byte[] fileData = (byte[])req.getParameter(oneKey);
+				byte[] fileData = oneFile.get() ; //(byte[])req.getParameter(oneKey);
+				
 				
                 log.debug("Calling uploadFile:" + oneKey);
                 final String subDir = multiDirs ? getSubDir(subDirs, subDirFields, fieldName) + File.separatorChar : "";
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.