title: $.ajax inside BeforeUpload Event - Plupload
body: <p>This app is an image uploading tool that uploads images directly from client browser to Amazon S3 using Plupload. So far, everything is working good except this issue.</p>
  
  <p>I've this code for<code>BeforeUpload</code> event.</p>
  
  <pre><code>init: {
      BeforeUpload: function (up, file) {
          $.ajax({
              url: '/ServerTime.ashx',
              dataType: 'text',
              data: { format: "yyyy-MM-dd_HH.mm.ss.fffffff" },
              type: 'POST',
              cache: false
          }).done(function (data) {
              console.log("Before setting ImageName: " + data);
              imageName = data + ".JPG";
              console.log("After setting ImageName: " + imageName);
              up.settings.multipart_params = {
                  'key': key,
                  'Filename': imageName,
                  'acl': 'public-read',
                  'success_action_status': '201',
                  'AWSAccessKeyId': accessKey,
                  'policy': policyDocument,
                  'signature': policySignature
              };
          });
      }
  }
  </code></pre>
  
  <p>However, I've this error when try to upload a file:</p>
  
  <blockquote>
    <p>HTTP Error. Upload URL might be wrong or doesn't exist.</p>
  </blockquote>
  
  <p>On Console, it is printing the expected result as follows:</p>
  
  <blockquote>
    <p>Before setting ImageName: 2014-04-04_13.33.45.1155072</p>
    
    <p>After setting ImageName: 2014-04-04_13.33.45.1155072.JPG</p>
  </blockquote>
  
  <p>I guess there is something wrong maybe because I'm using AJAX to get time from server. On the other  hand, trying the following code is working without any issue.</p>
  
  <pre><code>init: {
      BeforeUpload: function (up, file) {
          up.settings.multipart_params = {
              'key': "This_Is_Folder_Name/This_Is_File_Name.JPG",
              'Filename': "This_Is_File_Name.JPG",
              'acl': 'public-read',
              'success_action_status': '201',
              'AWSAccessKeyId': accessKey,
              'policy': policyDocument,
              'signature': policySignature
          };
      }
  }
  </code></pre>
  
  <p>Notice that, this time I'm using static names for <strong>Filename</strong> and <strong>key</strong>, and there is no AJAX either</p>
  
  <p>I really need help with this issue. Please suggest me. What I'm doing wrong with using AJAX to get server time and use it as file name?
  Thanks.</p>