I am trying to upload a file asynchronously using HTTP POST and jQuery, but I am having a strange problem: I cannot get the correct callback to start. When I upload a file, it returns an OK status with code 201 , and I can access the file in my S3 statement , but jQuery fails every time. After inspecting the XHR object a bit further, I came across:
Error: Permission denied for [http://192.168.2.247] to get property Window.document from [https://pentoolcn.aplusldesign.com.s3.amazonaws.com].
What could be the reason for this? This code is taken almost verbatim from http://developer.amazonwebservices.com/connect/entry!default.jspa?categoryID=139&externalID=1434&fromSearchPage=true and synchronously (normal form submission and page refresh), it worked perfectly.
My code is below.
<?php // CDN service options are Amazon S3 "S3" or None "none" [default] $CDN_SERVICE_TYPE = "S3"; $CDN_SERVICE_TYPE = 'none'; $CDN_ACCESS_KEY = '[CONFIDENTIAL]'; $CDN_SECRET_KEY = '[CONFIDENTIAL]'; $CDN_BUCKET = '[CONFIDENTIAL]'; $CDN_FOLDER = '[CONFIDENTIAL]'; // folder within bucket $CDN_ACL = 'public-read'; $CDN_MAX_FILE_SIZE = 20 * 1048576; // MB size limit $SUCCESS_REDIRECT = 'http://' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT']=='' ? '' : ':') . $_SERVER['SERVER_PORT'] . '/' . 'index.php'/*$_SERVER['SERVER_SELF']*/ . '?ok' ; // SendFileS3.php is URL from server root // process result from transfer, if query string present $query = $_SERVER['QUERY_STRING']; // setup transfer form $expTime = time() + (1 * 60 * 60); // now plus one hour (1 hour; 60 mins; 60secs) $expTimeStr = gmdate('Ymd\TH:i:s\Z', $expTime); //echo 'expTimeStr: '. $expTimeStr ."<BR/>"; //echo 'SUCCESS_REDIRECT: '. $SUCCESS_REDIRECT ."<BR/>"; // create policy document $policyDoc = ' {"expiration": "' . $expTimeStr . '", "conditions": [ {"acl": "' . $CDN_ACL . '"}, {"bucket": "' . $CDN_BUCKET . '"}, {"success_action_status": "201"}, ["starts-with", "$key", "' . $CDN_FOLDER . '"], [\'starts-with\', \'$folder\',\'\'], [\'starts-with\', \'$filename\', \'\'], [\'starts-with\',\'Upload\', \'\'], ["content-length-range", 0, ' . $CDN_MAX_FILE_SIZE . '], ] } '; // // Removed the success_action_redirect cause Flash doesn't like it $policyDocFlash = ' {"expiration": "' . $expTimeStr . '", "conditions": [ {"acl": "' . $CDN_ACL . '"}, {"bucket": "' . $CDN_BUCKET . '"}, {"success_action_status": "201"}, ["starts-with", "$key", "' . $CDN_FOLDER . '"], [\'starts-with\', \'$folder\',\'\'], [\'starts-with\', \'$filename\', \'\'], [\'starts-with\',\'Upload\', \'\'], ["content-length-range", 0, ' . $CDN_MAX_FILE_SIZE . '] ] } '; //echo "policyDoc: " . $policyDoc . '<BR/>'; // remove CRLFs from policy document $policyDoc = implode(explode('\r', $policyDoc)); $policyDoc = implode(explode('\n', $policyDoc)); $policyDoc64 = base64_encode($policyDoc); // encode to base 64 // create policy document signature $sigPolicyDoc = base64_encode(hash_hmac("sha1", $policyDoc64, $CDN_SECRET_KEY, TRUE/*raw_output*/)); //echo "policyDoc: " . $policyDoc . '<BR/>'; // remove CRLFs from policy document $policyDocFlash = implode(explode('\r', $policyDocFlash)); $policyDocFlash = implode(explode('\n', $policyDocFlash)); $policyDoc64Flash = base64_encode($policyDocFlash); // encode to base 64 // create policy document signature $sigPolicyDocFlash = base64_encode(hash_hmac("sha1", $policyDoc64Flash, $CDN_SECRET_KEY, TRUE/*raw_output*/)); ?> <html> <head> <title>S3 POST Form</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="css/uploadify.css" type="text/css" /> <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="js/jquery.uploadify.v2.1.4.min.js"></script> <script type="text/javascript" src="js/swfobject.js"></script> <script src="js/jquery.form.js" type="text/javascript" charset="utf-8"></script> <script src="js/jquery.validate.min.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> function setType(){ document.getElementById("Content-Type").value = getMIMEtype(document.getElementById("file").value); } var CDN_BUCKET = "<?php echo($CDN_BUCKET); ?>"; $(document).ready(function() { $("