Hi All,
I'm currently using cURL to upload a file from my server to S3 using AJAX to call the script.
So I have the following:
$fullfilepath = '/server/sitepath/files/' . $_POST['file'];
$upload_url = 'https://'.$_POST['buckets'].'.s3.amazonaws.com/';
$params = array(
'key'=>$_POST['key'],
'AWSAccessKeyId'=>$_POST['AWSAccessKeyId'],
'acl'=>$_POST['acl'],
'success_action_status'=>$_POST['success_action_status'],
'policy'=>$_POST['policy'],
'signature'=>$_POST['signature'],
'Content-Type'=>$_POST['Content-Type'],
'file'=>"@$fullfilepath"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
However, I'm getting an S3 error as follows when it posts and I'm unsure why because I'm not passing JSON to it.
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InvalidPolicyDocument</Code><Message>Invalid Policy: Invalid JSON.</Message><RequestId>B29469C6151BE0E8</RequestId><HostId>BFPk6W2kt1b6hTtx0mEq6dWdN/IhO0gNR5bct//7LAOwJxm1C3PrxS4RPv1blzJ8</HostId></Error>
I've googled it for the last hour or so and can't seem to figure it out. If I change the order of the Array fields, it gives me a different error - I believe the order of the posted fields is important somehow.
any help would be much appreciated!
C