jquery - S3 upload ajax, working in windows, failing on linux and mac -


i implemented plupload in application upload files s3 through jquery.

this works in windows locally. fails locally working on mac , on server linux. many hours have been spent talking aws support withouht solution.

create policy.php

<?php session_start(); include ($_server['document_root'] . '/sessionsetcookie.php'); $video_id = safe($_post['video_id']); $bucket = '';  $date1 = date("ymd"); $date2= date("ymd"); $date1 .= "t000000z"; $expire =  date('y-m-d\th:i:s.000\z', strtotime('+1 day')); $policy = '{         "expiration": "' . $expire . '",         "conditions": [             {                 "bucket": "' . $bucket . '"             },             {                 "acl": "public-read"             },                           {                 "x-amz-date": "'.$date1. '"             },             {                 "x-amz-meta-uuid": "14365123651274"             },             {                 "x-amz-credential": "keyhere/'.$date2.'/us-west-2/s3/aws4_request"             },             {                 "x-amz-algorithm": "aws4-hmac-sha256"             },                                             [                 "starts-with",                 "$key",                 "'.$globals['subdomain'].'/beeldbank/video_in/"             ],               [                 "starts-with",                 "$content-type",                 ""             ],              [                 "starts-with",                 "$name",                 ""             ],              [                 "starts-with",                 "$filename",                 ""             ],                [                 "starts-with",                 "$x-amz-meta-tag",                 ""             ],                           {                 "success_action_status": "201"             }         ]     }'; $policy = base64_encode($policy); echo $policy; ?> 

create signed policy $secret = 'secretkeyhere'; $policy = $_post['policy']; $signed = base64_encode(hash_hmac('sha1', $policy, $secret,true)); echo $signed;

jquery part

    var d = new date();     var month = d.getmonth()+1;     month = (month<10 ? '0' : '') + month;     var day = d.getdate();     day = (day<10 ? '0' : '') + day;     var year = d.getfullyear();     var datum2 = year +""+month+""+day;     var datum = year +""+month+""+day+"t000000z";              var uploader = new plupload.uploader({             runtimes : 'html5,flash,silverlight,html4',                browse_button : 'pickfiles', // can pass in id...             container: document.getelementbyid('container'), // ... or                      dom                 element                         url : "https://bucketname.s3.amazonaws.com:443/",                 file_date_name : "file",             multipart: true,             max_file_count : 1,             multi_selection : false,             multipart_params: {             'key': '<? echo $globals['subdomain'];?>/beeldbank/video_in/' + video_id, // use filename key             'filename': video_id, // adding keep consistency across runtimes             'acl': 'public-read',             'content-type': 'video/mp4',             'awsaccesskeyid' : 'access',             'policy':policy,             'signature': signed,             'success_action_status' : '201',             'x-amz-date': datum ,             'x-amz-meta-uuid' : "14365123651274",             'x-amz-credential': 'access/'+ datum2+ '/us-west-2/s3/aws4_request',             'x-amz-algorithm': 'aws4-hmac-sha256',             'x-amz-meta-tag': ""              },                              init: {                 postinit: function() {                     document.getelementbyid('filelist').innerhtml = '';                                                  },                            filesadded: function(up, files) {                                            plupload.each(files, function(file) {                                                document.getelementbyid('filelist').innerhtml += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatsize(file.size) + ') <b></b></div>';                     });                     uploader.start();                     $("#pickfiles").hide();                     $(".moxie-shim").hide();                      document.getelementbyid('console').innerhtml = "<?echo inhoud_return('upload_gestart');?>";                                        },                            uploadprogress: function(up, file) {                                        $("#uploadprogress").width(file.percent + '%');                       $("#procent").html(file.percent + "% ");                     if(file.percent == 100 )                     {                             uploaddone = "ready";                           document.getelementbyid('console').innerhtml = "<? echo inhoud_return('upload_voltooid');?>";                          }                 },                        error: function(up, err) {                                           document.getelementbyid('console').innerhtml += "\nerror #" + err.code + ": " + err.message;                 }             }         }); 

aws support suggested timezone differences between me locally, coworker on mac , server. have not checked out i'm not able to. has experienced problem before?


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -