Class TusClient


  • public class TusClient
    extends java.lang.Object
    This class is used for creating or resuming uploads.
    • Field Detail

      • TUS_VERSION

        public static final java.lang.String TUS_VERSION
        Version of the tus protocol used by the client. The remote server needs to support this version, too.
        See Also:
        Constant Field Values
    • Constructor Detail

      • TusClient

        public TusClient()
        Create a new tus client.
    • Method Detail

      • getUploadCreationURL

        public java.net.URL getUploadCreationURL()
        Get the current upload creation URL
        Returns:
        Current upload creation URL
      • enableResuming

        public void enableResuming​(@NotNull
                                   TusURLStore urlStore)
        Enable resuming already started uploads. This step is required if you want to use resumeUpload(TusUpload).
        Parameters:
        urlStore - Storage used to save and retrieve upload URLs by its fingerprint.
      • enableRemoveFingerprintOnSuccess

        public void enableRemoveFingerprintOnSuccess()
        Enable removing fingerprints after a successful upload.
        See Also:
        disableRemoveFingerprintOnSuccess()
      • disableRemoveFingerprintOnSuccess

        public void disableRemoveFingerprintOnSuccess()
        Disable removing fingerprints after a successful upload.
        See Also:
        enableRemoveFingerprintOnSuccess()
      • setHeaders

        public void setHeaders​(@Nullable
                               java.util.Map<java.lang.String,​java.lang.String> headers)
        Set headers which will be added to every HTTP requestes made by this TusClient instance. These may to overwrite tus-specific headers, which can be identified by their Tus-* prefix, and can cause unexpected behavior.
        Parameters:
        headers - The map of HTTP headers
        See Also:
        getHeaders(), prepareConnection(HttpURLConnection)
      • setConnectTimeout

        public void setConnectTimeout​(int timeout)
      • getConnectTimeout

        public int getConnectTimeout()
      • createUpload

        public TusUploader createUpload​(@NotNull
                                        TusUpload upload)
                                 throws ProtocolException,
                                        java.io.IOException
        Create a new upload using the Creation extension. Before calling this function, an "upload creation URL" must be defined using setUploadCreationURL(URL) or else this function will fail. In order to create the upload a POST request will be issued. The file's chunks must be uploaded manually using the returned TusUploader object.
        Parameters:
        upload - The file for which a new upload will be created
        Returns:
        Use TusUploader to upload the file's chunks.
        Throws:
        ProtocolException - Thrown if the remote server sent an unexpected response, e.g. wrong status codes or missing/invalid headers.
        java.io.IOException - Thrown if an exception occurs while issuing the HTTP request.
      • beginOrResumeUploadFromURL

        public TusUploader beginOrResumeUploadFromURL​(@NotNull
                                                      TusUpload upload,
                                                      @NotNull
                                                      java.net.URL uploadURL)
                                               throws ProtocolException,
                                                      java.io.IOException
        Begin an upload or alternatively resume it if the upload has already been started before. In contrast to createUpload(TusUpload) and resumeOrCreateUpload(TusUpload) this method will not create a new upload. The user must obtain the upload location URL on their own as this method will not send the POST request which is normally used to create a new upload. Therefore, this method is only useful if you are uploading to a service which takes care of creating the tus upload for yourself. One example of such a service is the Vimeo API. When called a HEAD request will be issued to find the current offset without uploading the file, yet. The uploading can be started by using the returned TusUploader object.
        Parameters:
        upload - The file for which an upload will be resumed
        uploadURL - The upload location URL at which has already been created and this file should be uploaded to.
        Returns:
        Use TusUploader to upload the remaining file's chunks.
        Throws:
        ProtocolException - Thrown if the remote server sent an unexpected response, e.g. wrong status codes or missing/invalid headers.
        java.io.IOException - Thrown if an exception occurs while issuing the HTTP request.
      • prepareConnection

        public void prepareConnection​(@NotNull
                                      java.net.HttpURLConnection connection)
        Set headers used for every HTTP request. Currently, this will add the Tus-Resumable header and any custom header which can be configured using setHeaders(Map),
        Parameters:
        connection - The connection whose headers will be modified.
      • uploadFinished

        protected void uploadFinished​(@NotNull
                                      TusUpload upload)
        Actions to be performed after a successful upload completion. Manages URL removal from the URL store if remove fingerprint on success is enabled
        Parameters:
        upload - that has been finished