Problems downloading blob directly to s3

I have the 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 this request passes, I get the following error:

<Code>AccessDenied</Code><Message>Invalid according to Policy: Policy Condition failed: ["starts-with", "$Filename", ""]</Message>

I have no idea what I'm doing wrong, I generate my blob as follows:

 function dataURItoBlob(dataURI) { var binary = atob(dataURI.split(',')[1]); var array = []; for (var i = 0; i < 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 is my 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-- 
+7
source share
1 answer

Having identified the problem, it is important to indicate the order of the form data, you must follow the correct order so that the data can be placed correctly.

+7
source

All Articles