title: Upload file on S3 using AmazonS3Client java
body: <p>I am using third party server which return me following things.
  1)url
  2)acl
  3)policy
  4)awsAccesskeyID
  5)Signature
  6)key
  I can upload file using following code</p>
  
  <pre><code>final File localFile = new File(localFilePath);
  
  final Part[] parts = { new StringPart("acl", acl),
      new StringPart("policy", policy),
      new StringPart("AWSAccessKeyId", awsAccessKeyId),
      new StringPart("signature", signature),
      new StringPart("key", key, HTTP.UTF_8), 
      new FilePart("file", localFile) };
  
      final MultipartRequestEntity mpRequestEntity = new MultipartRequestEntity(parts, filePost.getParams());
  
      filePost.setRequestEntity(mpRequestEntity);
      final HttpClient client = new HttpClient();
      try
      {
  
         status = client.executeMethod(filePost);
      }
  </code></pre>
  
  <p>But now I want to use AmazonS3Client using following code but its throwing exception that </p>
  
  <blockquote>
    <p>10-31 16:21:36.070: INFO/com.amazonaws.request(13882): Received error
    response: Status Code: 403, AWS Request ID: 51F7CB27E58F88FD, AWS
    Error Code: SignatureDoesNotMatch, AWS Error Message: The request
    signature we calculated does not match the signature you provided.
    Check your key and signing method., S3 Extended Request ID:
    YwNNsWOXg71vXY1VS0apHnHpHp4YVWRJ63xm8C7w36SYg1MNuIykw75YhQco5Lk7</p>
  </blockquote>
  
  <pre><code>        final AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials(awsAccessKeyId, key));
  
  
          // Create a list of UploadPartResponse objects. You get one of these
          // for each part upload.
          final List&lt;PartETag&gt; partETags = new ArrayList&lt;PartETag&gt;();
  
          // Step 1: Initialize.
          final InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(targetURL, key);
          final InitiateMultipartUploadResult initResponse = s3Client.initiateMultipartUpload(initRequest);
  
          final File file = new File(localFilePath);
          final long contentLength = file.length();
          long partSize = 5242880; // Set part size to 5 MB.
  
          try
          {
              // Step 2: Upload parts.
              long filePosition = 0;
              for ( int i = 1; filePosition &lt; contentLength; i++ )
              {
                  // Last part can be less than 5 MB. Adjust part size.
                  partSize = Math.min(partSize, (contentLength - filePosition));
  
                  // Create request to upload a part.
                  final UploadPartRequest uploadRequest = new UploadPartRequest().withBucketName(targetURL).withKey(key)
                          .withUploadId(initResponse.getUploadId()).withPartNumber(i).withFileOffset(filePosition)
                          .withFile(file).withPartSize(partSize);
  
                  // Upload part and add response to our list.
                  partETags.add(s3Client.uploadPart(uploadRequest).getPartETag());
  
                  filePosition += partSize;
              }
  
              // Step 3: complete.
              final CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest(targetURL, key,
                      initResponse.getUploadId(), partETags);
  
              s3Client.completeMultipartUpload(compRequest);
          }
          catch ( final Exception e )
          {
              s3Client.abortMultipartUpload(new AbortMultipartUploadRequest(targetURL, key, initResponse.getUploadId()));
              return false;
          }
          return true;
  </code></pre>
  
  <p>am I missing something here?</p>