1

Uploadify is a jQuery/Flash plugin for uploading multiple files. It's working great, except I can't figure out how trigger e-mail when all files are complete. If I try to add something like <% SendEmail(); %> to the onAllComplete parameter, it just sends the e-mail when the page loads.

Is there a way to do this within the handler recommended here or from this post? Or is there some way to trigger a post in the onAllComplete parameter?

<script type="text/javascript">
    // <![CDATA[
    var FirstName = $('[id$=HiddenField4]').val();
    var MiddleName = $('[id$=HiddenField5]').val();
    var ClientName = $('[id$=HiddenField6]').val();
    var queueSize = $('#fileInput').uploadifySettings('queueSize');
    $(document).ready(function() {
        $('#fileInput').uploadify({
            'uploader': 'scripts/uploadify/uploadify.swf',
            'script': 'Upload.ashx',
            'scriptData': { 'first': FirstName, 'middle': MiddleName, 'client': ClientName, 'queueSize': queueSize },
            'cancelImg': 'scripts/uploadify/cancel.png',
            'auto': true,
            'multi': true,
            'fileDesc': 'Image Files',
            'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg;*.pdf',
            'queueSizeLimit': 90,
            'sizeLimit': 10000000,
            'buttonText': 'Upload Documents',
            'folder': '/uploads',
            'onComplete': function(event, queueID, fileObj, response, data) {
                 alert(response);
            },
            'onAllComplete': function(event, queueID, fileObj, response, data) {
                 <% SendEmail(); %>
            },
            'buttonImg': 'images/upload.png'
         });
      });
      // ]]></script>

I've also tried queueSize declaring it as

var queueSize = $(".uploadifyQueueItem").size();

queueSize always posts as 0 when I debug my handler.

Community
  • 1
  • 1
David Fox
  • 10,603
  • 9
  • 50
  • 80
  • Can you include a code sample of what you're doing? The explanation you've given (with angle brackets) doesn't make sense. – Dan Esparza May 19 '10 at 16:08

2 Answers2

1

You could put the instruction to send the E-Mail into the script that receives the uploaded file (Upload.ashx in your case.)

That file will be called when the upload has been finalized.

An alternative would be making an Ajax call in the onComplete callback, calling another ashx script that sends out the E-Mails. Anyway, there is no JavaScript way of sending out the E-Mail, you will have to do that on the server side.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • The handler is executed once for every file. I need to send e-mail when all files (1 or more) are complete. – David Fox May 19 '10 at 16:17
  • @David I see. Then check out the last paragraph I just added. – Pekka May 19 '10 at 16:18
  • I understand there is no way to send e-mail client side, but I didn't know I could force an AJAX post from javascript. Should I look at jQuery.ajax() ? – David Fox May 19 '10 at 16:21
  • @David yup, if you're running jQuery already then that is the nicest way. (See BalusC's answer for an example.) – Pekka May 19 '10 at 16:28
  • awesome! thanks! Is it possible to post to .ashx? I did a .ajax() post to email.aspx and the page_load just sends the e-mail and dies. – David Fox May 19 '10 at 16:32
  • Sorry wasn't clear. I was informing you what I coded up. I should've said "Page_Load completes e-mail successfully and has given me tons of new ideas for jQuery ajax postbacks" :) I'm only familiar with .NET handler classes since I found this plugin, so I guess I'll have to read up no them – David Fox May 19 '10 at 17:39
1

You need to solve this at the server side. But Uploadify is an entirely client side script (JS+Flash). You need to write/invoke the mailing code in the server side which get invoked by an ajaxical call which you fire in onAllComplete. You can use jQuery.ajax or consorts for this.

E.g.

        'onAllComplete': function(event, queueID, fileObj, response, data) {
             $.post('somescript.aspx', paramsWhichSignalsServerToSendMail);
        },
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • The handler is executed once for every file. I need to send e-mail when all files (1 or more) are complete. – David Fox May 19 '10 at 16:18
  • you get the upvote for the code since I think it came in after Pekka's suggestion for the postback. – David Fox May 19 '10 at 16:31
  • Actually, after your comment and maybe also because pekka mentioned `onComplete` instead of `onAllComplete`. – BalusC May 19 '10 at 17:54