Re: Validating WOUpload form element before submitting
Re: Validating WOUpload form element before submitting
- Subject: Re: Validating WOUpload form element before submitting
- From: Randall Perry <email@hidden>
- Date: Wed, 21 Apr 2004 15:22:49 -0400
> So, yeah, there's no way to do this using WOFileUpload (that I can see).
>
I've redesigned my project a bit and found a way to check the filename
before proceeding with a WOFileUpload.
I'm able to check the filename within the WOFileUpload action method
uploadFile(), and set the flag fileNameOk. If the filename is ok the upload
preceeds, if it's not ok the method returns null.
There's a conditional on the upload page that checks fileNameOk and reports
an error if it's false so the user can try again.
Here's the uploadFile() method (note that the method returns the same page
regardless of whether the file upload succeeded -- I've got more work to do
on it) :
public WOComponent uploadFile()
{
String custDir = custInfo.userName();
custDir = "/Users/uploads/" + custDir;
String fileName = NSPathUtilities.lastPathComponent(theFileName);
if(!(fileNameOk = fileName.startsWith(custInfo.filecode()))) {
return null;
}
// Create the output path for the file on the application server
String outputFilePath = new String( custDir + File.separator + fileName
);
if ((fileName!=null) && (fileName.length()>0)) {
// Write the file out to the location
try {
FileOutputStream fileOutputStream = new
FileOutputStream(outputFilePath);
theFileData.writeToStream(fileOutputStream);
fileOutputStream.close();
} catch (IOException e) {
NSLog.err.appendln("Error writing file: " + e);
}
NSLog.out.appendln( "Wrote file to '" + outputFilePath + "'" );
NSLog.out.appendln( "MimeType: '" + theMimeType + "'" );
} else {
NSLog.out.appendln( "No File Uploaded" );
}
return this;
}
--
Randall Perry
sysTame
Xserve Web Hosting/Co-location
Website Development/Promotion
Mac Consulting/Sales
http://www.systame.com/
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.