PHP Amazon AWS S3 - Upload object using Pre-Signed URL
<p>I am trying to generate a URL that other system can use to upload a file to my S3 bucket. I looked over the documentation and similar issues, however, I cannot find the right solution.</p>

<p>I have tried creating the PreSigned URL multiple ways (<code>$this-&gt;s3</code> is a reference so S3Client):</p>

<p>1: </p>

<pre><code>       $signedUrl = $this-&gt;s3-&gt;getCommand(
            'PutObject',
            array(
                'Bucket' =&gt; $this-&gt;bucket,
                'Key' =&gt; 'recording_test.mp3',
                'Body' =&gt; ''
            )
        )-&gt;createPresignedUrl('+2 hours');
</code></pre>

<p>2:</p>

<pre><code>    $command = $this-&gt;s3-&gt;getCommand('PutObject', array('Bucket' =&gt; $this-&gt;bucket, 'Key' =&gt; 'recording_test3.mp3', 'Body' =&gt; ''));

    $request = $command-&gt;prepare();

    $signedUrl = $this-&gt;s3-&gt;createPresignedUrl($request, '+2 hours');
</code></pre>

<p>When trying to simply access the URL I get following error:</p>

<pre><code>The request signature we calculated does not match the signature you provided. Check your key and signing method.
</code></pre>

<p>I have also tried it this way:
        $key = 'recording_test2.mp3';
        $url = $this->bucket.'/'.$key;</p>

<pre><code>    $request = $this-&gt;s3-&gt;put($url);

    $signedUrl = $this-&gt;s3-&gt;createPresignedUrl($request, '+2 hours');
</code></pre>

<p>However, this generates a URL in format of <code>s3.amazonaws.com/bucket/key...</code>, which yields an error about invalid endpoint, and that endpoint in format <code>bucket.s3.amazonaws.com/key...</code> should be used. Manually changing the URL gives the same invalid signature error as per above.</p>

<p>I cannot see what am I doing wrong or any other way to generate the PreSigned URL?</p>

<p>Thanks for help</p>