Class MultipartObjectAssembler


  • public class MultipartObjectAssembler
    extends Object
    MultiPartObjectAssembler provides a simplified interaction with uploading large objects using multi-part uploads.

    An assembler can be used begin a new upload, or resume a previous one. Parts are be added to the assembler in order, and the assembler will handle all transfers and part numbering. Users can reference the returned manifest to watch/monitor updates to the upload as new parts are added or parts complete.

    Note, a new assembler instance should be used for every multi-part upload. Once initialized (or resumed), an assembler cannot be reused.

    • Constructor Detail

      • MultipartObjectAssembler

        @Deprecated
        public MultipartObjectAssembler​(ObjectStorage service,
                                        String namespaceName,
                                        String bucketName,
                                        String objectName,
                                        boolean allowOverwrite,
                                        ExecutorService executorService)
        Deprecated.
        use builder() instead
        Creates a new assembler.
        Parameters:
        service - The object storage service
        namespaceName - The namespace to use
        bucketName - The bucket to use
        objectName - The final object name.
        allowOverwrite - Allow uploads to overwrite existing parts with the same part number
        executorService - The executor service to use
    • Method Detail

      • newRequest

        public MultipartManifest newRequest​(String contentType,
                                            String contentLanguage,
                                            String contentEncoding,
                                            Map<String,​String> opcMeta)
        Initialize a new multi-part upload request.
        Parameters:
        contentType - The content-type of the object, optional
        contentLanguage - The content-language of the object, optional
        contentEncoding - The content-encoding of the object, optional
        Returns:
        A new manifest instance representing the object and it’s progress.
      • resumeRequest

        public MultipartManifest resumeRequest​(String uploadId)
        Resumes an existing multi-part upload using the upload ID.
        Parameters:
        uploadId - The upload ID.
        Returns:
        A new manifest instance representing the object and it’s progress.
      • addPart

        public int addPart​(File file,
                           String md5)
        Add the next part to the upload.

        Parts will be committed in the order submitted.

        Calling this will set the ifNoneMatch value and will not allow overwriting existing parts.

        Parameters:
        file - The file to upload as the next part
        md5 - The MD5 checksum of the file, optional
        Returns:
        The part number assigned to this part
      • addPart

        public int addPart​(InputStream stream,
                           long contentLength,
                           String md5)
        Add the next part to the upload.

        Parts will be committed in the order submitted.

        We allow part overwrites to facilitate retries.

        Parameters:
        stream - The stream to upload as the next part
        contentLength - The content length of the part
        md5 - The MD5 checksum, optional
        Returns:
        The part number assigned to this part
      • addPart

        public int addPart​(InputStream stream,
                           long contentLength,
                           String checksum,
                           String checksumAlgorithm)
        Adds the next part to the upload.

        Parts will be committed in the order submitted.

        We allow part overwrites to facilitate retries.

        Parameters:
        stream - The stream to upload as the next part
        contentLength - The content length of the part
        checksum - The checksum of the part, optional
        checksumAlgorithm - The checksum algorithm used, optional (e.g., “CRC32C”)
        Returns:
        The part number assigned to this part
        Throws:
        IllegalStateException - if the assembler has not been initialized or the upload has been aborted
      • setPart

        public void setPart​(File file,
                            String md5,
                            int partNum)
        Adds a part to the upload.

        The part will be ordered based on the part number provided.

        This is useful to retry a failed part, to explicitly control the part numbering, or overwrite an existing part.

        Calling this will not set the ifNoneMatch value and will allow overwriting existing parts.

        Parameters:
        file - The file to upload
        md5 - The MD5 checksum, optional
        partNum - The part number to to assign to the part
      • setPart

        public void setPart​(InputStream stream,
                            long contentLength,
                            String md5,
                            int partNum)
        Adds a part to the upload.

        The part will be ordered based on the part number provided.

        This is useful to retry a failed part, to explicitly control the part numbering, or overwrite an existing part.

        Calling this will not set the ifNoneMatch value and will allow overwriting existing parts.

        Parameters:
        stream - The stream to upload
        contentLength - The content length of the part
        md5 - The MD5 checksum, optional
        partNum - The part number to to assign to the part
      • setPart

        public void setPart​(InputStream stream,
                            long contentLength,
                            String checksum,
                            String checksumAlgorithm,
                            int partNum)
        Adds a part to the upload.

        The part will be ordered based on the part number provided.

        This method is for setting parts with additional checksum algorithms.

        Calling this will not set the ifNoneMatch value and will allow overwriting existing parts.

        Parameters:
        stream - The stream to upload
        contentLength - The content length of the part
        checksum - The checksum value, optional
        checksumAlgorithm - The checksum algorithm used
        partNum - The part number to assign to the part
      • abort

        public AbortMultipartUploadResponse abort()
        Aborts the current multi-part assembly and all uploads that are currently in progress.
        Returns:
        abort response
      • commit

        public CommitMultipartUploadResponse commit()
        Commits the multi-part upload after all in-progress uploads have completed.

        This is a blocking call, and throws IllegalStateException if you try to commit an upload in which the Manifest reports it is not successful (MultipartManifest.isUploadSuccessful()).

        Returns:
        The commit response.
      • setOpcClientRequestId

        public void setOpcClientRequestId​(String opcClientRequestId)
        The opcClientRequestId to send for all requests related to this multi-part upload.