This is a migrated thread and some comments may be shown as answers.

OnClientFileUploading question

2 Answers 61 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 05 Sep 2013, 04:50 PM
Thanks all in advance.

We understand how the set_cancel method works within the OnClientFileUploading event.  However, we need to confirm the behaviour when set_cancel(true) is executed.  Does it cancel all the files in a multiple file upload or just the one file?

Also, we would like to do some custom validation within the OnClientFileUploading event but need to get the file extension in order to do this.  We see how to issue args.get_fileName() but need to inspect the extension based on our own invalid extension list.  Is there a file extension method available for this?

Thanks...Bob Baldwin
Trabon Solutions

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Sep 2013, 06:13 AM
Hi Bob,

The OnClientFileUploading client-side event occurs when each file has started uploading. To make it more clear suppose you are selecting five files to upload, then this event will fire prior to uploading each file. If you are simply giving set_cancel(true) inside the OnClientFileUploading method, then set_cancel(true) will be executed each time when the OnClientFileUploading event fires and as a result all the uploading get cancelled.

Please have a look at the following JavaScript I tried to extract the file extension from the file name and cancel the upload of files with extensions other than "jpg".

JavaScript:
<script type="text/javascript">
    function OnClientFileUploading(sender, args) {
        var fileextension = args.get_fileName().split('.').pop();
        if (fileextension != "jpg") {
            args.set_cancel(true);
        }
        else {
            args.set_cancel(false);
        }
    }
</script>

Thanks,
Shinu.
0
Bob
Top achievements
Rank 1
answered on 06 Sep 2013, 12:53 PM
Thanks Shinu,

That answered our questions.

Bob Baldwin
Trabon Solutions
Tags
AsyncUpload
Asked by
Bob
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Bob
Top achievements
Rank 1
Share this question
or