0

I've tried a number of different methods following examples from this website and other sources but I am hitting a brick wall. After failing to get this working after over a month of daily trying different things I have narrowed it down to the following using the latest version of the AWS SDK for aws-php-sdk-2.7.1. You think it would work right? What I am attempting to do is allow users to edit a web page using javascript, capture the markup in a Div and PUT it to a bucket using a signed URL on Amazon S3. I'm getting an error that my signature method is incorrect. Am I under the wrong conclusion that the SDK is supposed to do this work for me or am I doing something wrong. My Key and Password are working fine using JAVA with PUT yet I need a solution that works on the client side. Other schemes without the SDK used other means to sign the URL but I could not get those to work here either… I could really use some help. Thank you.

This is where I am currently.

My Cors on the bucket: ////////////////////////////////////////////////////////////

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedOrigin>*:8443</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>DELETE</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

2 Answers2

0

As noted on the jQuery website (http://api.jquery.com/jquery.ajax/), not all browsers support "PUT" and "DELETE" requests.

AlexL
  • 1,699
  • 12
  • 20
  • I've tried it from both recent versions Firefox and Safari... Should be working... "HTML forms (up to HTML version 4 and XHTML 1) only support GET and POST as HTTP request methods. However, GET, POST, PUT and DELETE are supported by the implementations of XMLHttpRequest (i.e. AJAX calls) in all the major web browsers (IE, Firefox, Opera)." http://stackoverflow.com/questions/165779/are-the-put-delete-head-etc-methods-available-in-most-web-browsers – solarfingers Oct 25 '14 at 00:21
0

The request from the browser contains a Content-Type header which isn't present in the presigned URL, causing the signature to be invalid. You need to include that information in the signature, just as if you were performing the PUT operation directly in PHP. I wasn't able to find documentation matching the syntax you're using to perform that request, but a Github issue for the AWS SDK indicates that the following should work:

$command = $client->getCommand("PutObject", array(
    'Bucket'      => ...,
    'Key'         => ...,
    'ContentType' => 'txt/html; charset=utf-8',
));

$url = $command->createPresignedUrl('+10 minutes');

As an aside, the Content-Type you're using currently is invalid. (This won't prevent the upload from working, but will make it not display correctly in browsers.) You want text/html, not txt/html; MIME types are generally not abbreviated.

  • I've tried this form before... Whenever I use createPredisgnedUrl('+10 minutes') without the $request before the time I get the Fatal Error: Call to undefined method Guzzle\Service\Command\OperationCommand::createPresignedUrl... I tried it again as you suggested but no joy. I also tried it using: $signedUrl = $client->createPresignedUrl($command, '+10 minutes') and I get: Warning: required argument missing AND Fatal Error: Call to undefined method Guzzle\Service\Command\OperationCommand::getQuery – solarfingers Oct 25 '14 at 01:56
  • Are you *sure* you're using the current version of the AWS SDK? –  Oct 25 '14 at 03:57
  • Yes, as current as last week ... v2.7.1. – solarfingers Oct 25 '14 at 15:19
  • I just checked v2.7.2 is out. I will give this a try. – solarfingers Oct 25 '14 at 15:20
  • Well I have installed v2.7.2 and still no joy. Am I missing a dependency? As above I am only using Aws\Common\Aws, Aws\Common\Region, and Aws\S3\S3Client... – solarfingers Oct 28 '14 at 15:52