[Webtest] Revised file upload patch

Brian O'Kelley webtest@lists.canoo.com
Tue, 3 Jun 2003 20:02:18 -0400


This patch handles bad paths better and works with empty parameters.

Index: ClickButton.java
===================================================================
RCS file:
/repositories/cvs/public/webtest/src/com/canoo/webtest/steps/request/ClickBu
tton.java,v
retrieving revision 1.8
diff -r1.8 ClickButton.java
16a17
> import java.io.File;
232,234c233,258
< 
<         form.setParameter(parameterHolder.getName(),
<                 (String []) parameterValues.toArray(new
String[parameterValues.size()]));
---
> 		if (form.isFileParameter(parameterHolder.getName())) {
> 			System.out.println("Parameter is a file param: " +
> 					parameterHolder.getName() + " with "
+
> 					parameterValues.size() + " values.")
;
> 			List files = new ArrayList() ;
> 			for (int i = 0 ; i < parameterValues.size() ; i++) {
> 				String path = (String)parameterValues.get(i)
;
> 				if (path.length() > 0) {
> 					File uploadFile = new File(path) ;
> 					if (uploadFile.exists()) {
> 						files.add(new
UploadFileSpec(uploadFile)) ;
> 					} else {
> 						System.err.println("Warning:
File not found: " +
> 								uploadFile)
;
> 					}
> 				}
> 			}
> 			if (files.size() > 0) {
> 				form.setParameter(parameterHolder.getName(),
>
(UploadFileSpec[])files.toArray(
> 						new
UploadFileSpec[files.size()])) ;
> 			}
> 		} else {
>         	form.setParameter(parameterHolder.getName(),
> 					(String [])
parameterValues.toArray(new String[parameterValues.size()]));
> 		}