I am trying to download an image file from my Trigger.io mobile application directly to Amazon S3 (see here http://aws.amazon.com/articles/1434 ). I can do this on the Internet without any problems using jQuery and the API FormDataas follows:
var fd = new FormData();
key = 'test.jpg'
fd.append('key', key);
fd.append('acl', 'public-read');
fd.append('Content-Type', file.type);
fd.append('AWSAccessKeyId', key_id);
fd.append('policy', policy_base64);
fd.append('signature', signature);
fd.append('file', file);
$.ajax({
type: 'POST',
url: 'https://' + bucket + '.s3.amazonaws.com/',
processData: false,
contentType: false,
data: fd,
success: function(response) {
}
});
However, I cannot get this to work with the Forge request APIs. This is what I tried:
forge.request.ajax({
type: 'POST',
url: 'https://' + bucket + '.s3.amazonaws.com/',
fileUploadMethod: 'raw',
files: [file],
data: fd,
headers: { 'Content-Type': 'multipart/form-data', 'x-amz-acl': 'public-read' },
success: function(response) {
}
});
But I get the following error from Amazon:
<Code>PreconditionFailed</Code>
<Message>At least one of the pre-conditions you specified did not hold</Message>
<Condition>Bucket POST must be of the enclosure-type multipart/form-data</Condition>
I will get around this forge.requestcompletely in favor $.ajax, but mine filewas obtained using the Forge API files and just displays on S3 as [object Object](I assume this is a Forge file, not a true HTML file object <input />).
, Trigger.io Amazon S3 FormData Forge API? ! !