Class AWS4SignerForChunkedUpload


  • public class AWS4SignerForChunkedUpload
    extends AWS4SignerBase
    Sample AWS4 signer demonstrating how to sign 'chunked' uploads This code was taken from Amazon Example. No copyright found.
    • Field Detail

      • STREAMING_BODY_SHA256

        public static final String STREAMING_BODY_SHA256
        SHA256 substitute marker used in place of x-amz-content-sha256 when employing chunked uploads
        See Also:
        Constant Field Values
    • Constructor Detail

      • AWS4SignerForChunkedUpload

        public AWS4SignerForChunkedUpload​(URL endpointUrl,
                                          String httpMethod,
                                          String serviceName,
                                          String regionName)
    • Method Detail

      • computeSignature

        public String computeSignature​(Map<String,​String> headers,
                                       Map<String,​String> queryParameters,
                                       String bodyHash,
                                       String awsAccessKey,
                                       String awsSecretKey)
        Computes an AWS4 signature for a request, ready for inclusion as an 'Authorization' header.
        Parameters:
        headers - The request headers; 'Host' and 'X-Amz-Date' will be added to this set.
        queryParameters - Any query parameters that will be added to the endpoint. The parameters should be specified in canonical format.
        bodyHash - Precomputed SHA256 hash of the request body content; this value should also be set as the header 'X-Amz-Content-SHA256' for non-streaming uploads.
        awsAccessKey - The user's AWS Access Key.
        awsSecretKey - The user's AWS Secret Key.
        Returns:
        The computed authorization string for the request. This value needs to be set as the header 'Authorization' on the subsequent HTTP request.
      • calculateChunkedContentLength

        public static long calculateChunkedContentLength​(long originalLength,
                                                         long chunkSize)
        Calculates the expanded payload size of our data when it is chunked
        Parameters:
        originalLength - The true size of the data payload to be uploaded
        chunkSize - The size of each chunk we intend to send; each chunk will be prefixed with signed header data, expanding the overall size by a determinable amount
        Returns:
        The overall payload size to use as content-length on a chunked upload
      • constructSignedChunk

        public byte[] constructSignedChunk​(int userDataLen,
                                           byte[] userData)
        Returns a chunk for upload consisting of the signed 'header' or chunk prefix plus the user data. The signature of the chunk incorporates the signature of the previous chunk (or, if the first chunk, the signature of the headers portion of the request).
        Parameters:
        userDataLen - The length of the user data contained in userData
        userData - Contains the user data to be sent in the upload chunk
        Returns:
        A new buffer of data for upload containing the chunk header plus user data