• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Validating WOUpload form element before submitting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Validating WOUpload form element before submitting


  • Subject: Re: Validating WOUpload form element before submitting
  • From: Jonathan Rochkind <email@hidden>
  • Date: Wed, 21 Apr 2004 14:56:22 -0500

Of course you can do that, but keep in mind that you have not cancelled the upload. The browser will upload the entire file before it retrieves the page saying either "upload okay" or "upload not okay". You are just choosing to ignore the file in some cases.

--Jonathan

At 3:22 PM -0400 4/21/04, Randall Perry wrote:
> 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.
_______________________________________________
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.


References: 
 >Re: Validating WOUpload form element before submitting (From: Randall Perry <email@hidden>)

  • Prev by Date: Null Value
  • Next by Date: Editing Context Redux...
  • Previous by thread: Re: Validating WOUpload form element before submitting
  • Next by thread: Permission issue
  • Index(es):
    • Date
    • Thread