|
Rank: Newbie Groups: Member
Joined: 8/24/2012 Posts: 5
|
I need to prevent certain files from being uploaded. The allowed extensions property sets the allowed extensions. Is there anyway to do it? I thought I could handle ClientSideOnStart and use the AJAXUploader.getCurrentFileName() function to check the filename of the file being uploaded. But it's returning undefined. Here's how I'm handling ClientSideOnStart: Quote: <eo:AJAXUploader ID="AJAXFileUploader" runat="server" OnFileUploaded="AJAXFileUploader_FileUploaded" ClientSideOnError="FileUploaderError" ClientSideOnLoad="HideProgBar" ClientSideOnStart="ShowProgBar" ClientSideOnDone="UploadDone" MaxDataSize="15360">
Quote: function ShowProgBar(sender) { var senderName = sender.getId(); var progBarName = senderName + '_ProgressBar'; alert(sender.getCurrrentFileName()); ... }
But here the call to getCurrentFileName returns nothing. Can I handle this from client side? I know I'll have to take care of this on the server side as well.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
getCurrentFileName only works when the upload is already in progress. AllowedExtension is the only way to prevent a file being uploaded.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 8/24/2012 Posts: 5
|
So, how about ClientSideOnProgress event handler?? I couldn't get it to work from it either. Maybe the file is too small for the handler to be called on time??
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
I believe ClientSideOnProgress should always be called at least once. However there is nothing you can do inside that handler except for updating UI to give user visual feedbacks. What exactly do you want to do? You either disallow based on file name or file content. If you wish to disallow by file name, then AllowedExtension should be sufficient. If you wish to disallow by file content, then you have to wait until the server have the file first, that means the upload has to be complete first.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 8/24/2012 Posts: 5
|
My requirement is that the uploader should allow for all file extensions except for executables like exe or bat. Since we do not have a list of allowed extensions, I cannot use the AllowedExtension property. From the ClientSideOnProgress, I wanted to check the file extension and if it is an executable, I would cancel the upload. Quote: <eo:AJAXUploader ID="AJAXFileUploader" runat="server" OnFileUploaded="AJAXFileUploader_FileUploaded" ClientSideOnError="FileUploaderError" ClientSideOnLoad="HideProgBar" ClientSideOnStart="ShowProgBar" ClientSideOnDone="UploadDone" MaxDataSize="15360" ClientSideOnProgress="OnUploadProgress">
Quote: function OnUploadProgress(uploader, total, received ) { alert(uploader.getCurrentFileName()); }
Apparently this never fired. I'm working on the server side implementation now.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
I see. Using server side implementation is probably the safest way. User can always bypass client side JavaScript code. In the future probably a "DisallowedExtension" property would make such task much easier (you would still want to check on the server side even with this property though).
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 8/24/2012 Posts: 5
|
I agree. I just didn't want to waste a postback which would be appreciated by a benign user. Thank you for the clarification.
|
|
Rank: Newbie Groups: Member
Joined: 8/24/2012 Posts: 5
|
It turns out I was right.. I was looking at the wrong uploader. The last code example worked for me in the end. Thank you for the discussion.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
You are very welcome. Glad to hear that it works for you. Please feel free to let us know if there is anything else.
|
|