javascript - Having problems uploading blob directly to s3 -
i have following code:
var fd = new formdata(); var key = "events/" + (new date).gettime() + '-'; fd.append('key', key); fd.append('acl', acl); fd.append('content-type', "image/jpeg"); fd.append('awsaccesskeyid', awsaccesskeyid); fd.append('policy', policy); fd.append('name', "policy13492345"); fd.append('success_action_status', "201"); fd.append('signature', signature); fd.append("file", blob); fd.append("filename", filename + ".jpg"); var xhr = new xmlhttprequest(); xhr.upload.addeventlistener("progress", uploadprogress, false); xhr.addeventlistener("load", uploadcomplete, false); xhr.addeventlistener("error", uploadfailed, false); xhr.addeventlistener("abort", uploadcanceled, false); xhr.open('post', 'https://s3.amazonaws.com/' + bucket + '/', true); xhr.send(fd);
when request goes through following error:
<code>accessdenied</code><message>invalid according policy: policy condition failed: ["starts-with", "$filename", ""]</message>
i have no idea doing wrong, generate blob so:
function datauritoblob(datauri) { var binary = atob(datauri.split(',')[1]); var array = []; (var = 0; < binary.length; i++) { array.push(binary.charcodeat(i)); } var mimestring = datauri.split(',')[0].split(':')[1].split(';')[0] return new blob([new uint8array(array)], { type: mimestring }); }
this request:
------webkitformboundaryxh8thnhamdhzquxe content-disposition: form-data; name="key" events/1367541109750- ------webkitformboundaryxh8thnhamdhzquxe content-disposition: form-data; name="acl" private ------webkitformboundaryxh8thnhamdhzquxe content-disposition: form-data; name="content-type" image/jpeg ------webkitformboundaryxh8thnhamdhzquxe content-disposition: form-data; name="awsaccesskeyid" asdfasdffasdfsdfaadsfhhvdq ------webkitformboundaryxh8thnhamdhzquxe content-disposition: form-data; name="policy" fsny29udfuz2unlcawlcaxmdawmdawmdbdlaogicagicasdfasdfagifsgj3n0yxj0cy13axrojywgjyrrzxknlcanjybdlaogicagicagifsgj3n0yxj0cy13axrojywgjyrdb250zw50lvr5cgunlcanasdfjybdlao ------webkitformboundaryxh8thnhamdhzquxe content-disposition: form-data; name="name" policy134722343242345 ------webkitformboundaryxh8thnhamdhzquxe content-disposition: form-data; name="success_action_status" 201 ------webkitformboundaryxh8thnhamdhzquxe content-disposition: form-data; name="signature" basdfasdftwa/9asdfasdfx3/zasdfadsft6g= ------webkitformboundaryxh8thnhamdhzquxe content-disposition: form-data; name="file"; filename="blob" content-type: image/jpeg ------webkitformboundaryxh8thnhamdhzquxe content-disposition: form-data; name="filename" c:\fakepath\495845894.jpg ------webkitformboundaryxh8thnhamdhzquxe--
figured out issue, ordering formdata important, must follow correct order in order data post correctly.
Comments
Post a Comment