title: Upload to s3 with curl using pre-signed URL (getting 403)
body: <p>I'm using curl to call into a Java ReST API to retrieve a URL. Java then generates a pre-signed URL for S3 upload using my S3 credentials, and returns that in the ReST reply. Curl takes the URL and uses that for upload to S3, but S3 returns 403 "The request signature we calculated does not match the signature you provided. Check your key and signing method."</p>
  
  <p>Here is the code I'm using to generate the pre-signed URL:</p>
  
  <pre><code>public class S3Util {
      static final AmazonS3 s3 = new AmazonS3Client( new AWSCredentials() {
          @Override
          public String getAWSAccessKeyId() {
              return "XXXXXXX";
          }
          @Override
          public String getAWSSecretKey() {
              return "XXXXXXXXXXXXXX";
          }
      });
      static final String BUCKET = "XXXXXXXXXXXXXXXXXXXXXXXXXXX";
  
      static public URL getMediaChunkURL( MediaChunk mc, HttpMethod method ) {
          String key = ...
          //way in the future (for testing)...
          Date expiration = new Date( System.currentTimeMillis() + CalendarUtil.ONE_MINUTE_IN_MILLISECONDS*60*1000 );
  
          GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(BUCKET, key, method);
          req.setExpiration(expiration);
          req.addRequestParameter("Content-Type", "application/octet-stream");
  
          //this gets passed to the end user:
          return s3.generatePresignedUrl(req);
      }
  }
  </code></pre>
  
  <p>and in curl, run from bash, I execute this:</p>
  
  <pre><code>echo Will try to upload chunk to ${location}
  curl -i -X POST \
          -F 'Content-Type=application/octet-stream' \
          -F "file=@${fileName}" \
          ${location} || (echo upload chunk failed. ; exit 1 )
  </code></pre>
  
  <p>Among other things, I have tried PUT, and I have tried "Content-type" (lowercase T). I realize I'm missing something (or somethings) obvious, but after reading the appropriate docs, googling and looking at lots of similar questions I'm not sure what that is. I see lots of hints about required headers, but I thought the resigned URL was supposed to eliminate those needs. Maybe not?</p>
  
  <p>TIA!</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Just to be clear, I have tested downloads, and that works fine.</p>
  
  <p>Java looks like:</p>
  
  <pre><code>GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(BUCKET, key, HttpMethod.GET);
  req.setExpiration(expiration);
  </code></pre>
  
  <p>and curl is simply:</p>
  
  <pre><code>curl -i ${location}
  </code></pre>