Package io.tus.java.client
Class TusClient
java.lang.Object
io.tus.java.client.TusClient
This class is used for creating or resuming uploads.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringVersion of the tus protocol used by the client. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbeginOrResumeUploadFromURL(@NotNull TusUpload upload, @NotNull URL uploadURL) Begin an upload or alternatively resume it if the upload has already been started before.createUpload(@NotNull TusUpload upload) Create a new upload using the Creation extension.voidDisable removing fingerprints after a successful upload.voidDisable resuming started uploads.voidEnable removing fingerprints after a successful upload.voidenableResuming(@NotNull TusURLStore urlStore) Enable resuming already started uploads.intReturns the Connection Timeout.Get the HTTP headers which should be contained in every request and were configured usingsetHeaders(Map).getProxy()Get the current proxy used for all requests.Get the current upload creation URL.voidprepareConnection(@NotNull HttpURLConnection connection) Set headers used for every HTTP request.booleanGet the current status if removing fingerprints after a successful upload.resumeOrCreateUpload(@NotNull TusUpload upload) Try to resume an upload usingresumeUpload(TusUpload).resumeUpload(@NotNull TusUpload upload) Try to resume an already started upload.booleanGet the current status if resuming.voidsetConnectTimeout(int timeout) Sets the timeout for a Connection.voidsetHeaders(@Nullable Map<String, String> headers) Set headers which will be added to every HTTP requestes made by this TusClient instance.voidSet the proxy that will be used for all requests.voidsetUploadCreationURL(URL uploadCreationURL) Set the URL used for creating new uploads.protected voiduploadFinished(@NotNull TusUpload upload) Actions to be performed after a successful upload completion.
-
Field Details
-
TUS_VERSION
Version of the tus protocol used by the client. The remote server needs to support this version, too.- See Also:
-
-
Constructor Details
-
TusClient
public TusClient()Create a new tus client.
-
-
Method Details
-
setUploadCreationURL
Set the URL used for creating new uploads. This is required if you want to initiate new uploads usingcreateUpload(io.tus.java.client.TusUpload)orresumeOrCreateUpload(io.tus.java.client.TusUpload)but is not used if you only resume existing uploads.- Parameters:
uploadCreationURL- Absolute upload creation URL
-
getUploadCreationURL
Get the current upload creation URL.- Returns:
- Current upload creation URL
-
setProxy
Set the proxy that will be used for all requests.- Parameters:
proxy- Proxy to use
-
getProxy
Get the current proxy used for all requests.- Returns:
- Current proxy
-
enableResuming
Enable resuming already started uploads. This step is required if you want to useresumeUpload(TusUpload).- Parameters:
urlStore- Storage used to save and retrieve upload URLs by its fingerprint.
-
disableResuming
public void disableResuming()Disable resuming started uploads.- See Also:
-
resumingEnabled
public boolean resumingEnabled()Get the current status if resuming.- Returns:
- True if resuming has been enabled using
enableResuming(TusURLStore) - See Also:
-
enableRemoveFingerprintOnSuccess
public void enableRemoveFingerprintOnSuccess()Enable removing fingerprints after a successful upload.- See Also:
-
disableRemoveFingerprintOnSuccess
public void disableRemoveFingerprintOnSuccess()Disable removing fingerprints after a successful upload.- See Also:
-
removeFingerprintOnSuccessEnabled
public boolean removeFingerprintOnSuccessEnabled()Get the current status if removing fingerprints after a successful upload.- Returns:
- True if resuming has been enabled using
enableResuming(TusURLStore) - See Also:
-
setHeaders
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
Get the HTTP headers which should be contained in every request and were configured usingsetHeaders(Map).- Returns:
- The map of configured HTTP headers
- See Also:
-
setConnectTimeout
public void setConnectTimeout(int timeout) Sets the timeout for a Connection.- Parameters:
timeout- in milliseconds
-
getConnectTimeout
public int getConnectTimeout()Returns the Connection Timeout.- Returns:
- Timeout in milliseconds.
-
createUpload
public TusUploader createUpload(@NotNull @NotNull TusUpload upload) throws ProtocolException, IOException Create a new upload using the Creation extension. Before calling this function, an "upload creation URL" must be defined usingsetUploadCreationURL(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 returnedTusUploaderobject.- Parameters:
upload- The file for which a new upload will be created- Returns:
- Use
TusUploaderto 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.IOException- Thrown if an exception occurs while issuing the HTTP request.
-
resumeUpload
public TusUploader resumeUpload(@NotNull @NotNull TusUpload upload) throws FingerprintNotFoundException, ResumingNotEnabledException, ProtocolException, IOException Try to resume an already started upload. Before call this function, resuming must be enabled usingenableResuming(TusURLStore). This method will look up the URL for this upload in theTusURLStoreusing the upload's fingerprint (seeTusUpload.getFingerprint()). After a successful lookup a HEAD request will be issued to find the current offset without uploading the file, yet.- Parameters:
upload- The file for which an upload will be resumed- Returns:
- Use
TusUploaderto upload the remaining file's chunks. - Throws:
FingerprintNotFoundException- Thrown if no matching fingerprint has been found inTusURLStore. UsecreateUpload(TusUpload)to create a new upload.ResumingNotEnabledException- Throw if resuming has not been enabled usingenableResuming(TusURLStore).ProtocolException- Thrown if the remote server sent an unexpected response, e.g. wrong status codes or missing/invalid headers.IOException- Thrown if an exception occurs while issuing the HTTP request.
-
beginOrResumeUploadFromURL
public TusUploader beginOrResumeUploadFromURL(@NotNull @NotNull TusUpload upload, @NotNull @NotNull URL uploadURL) throws ProtocolException, IOException Begin an upload or alternatively resume it if the upload has already been started before. In contrast tocreateUpload(TusUpload)andresumeOrCreateUpload(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 returnedTusUploaderobject.- Parameters:
upload- The file for which an upload will be resumeduploadURL- The upload location URL at which has already been created and this file should be uploaded to.- Returns:
- Use
TusUploaderto 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.IOException- Thrown if an exception occurs while issuing the HTTP request.
-
resumeOrCreateUpload
public TusUploader resumeOrCreateUpload(@NotNull @NotNull TusUpload upload) throws ProtocolException, IOException Try to resume an upload usingresumeUpload(TusUpload). If the method call throws anResumingNotEnabledExceptionorFingerprintNotFoundException, a new upload will be created usingcreateUpload(TusUpload).- Parameters:
upload- The file for which an upload will be resumed- Returns:
TusUploaderinstance.- Throws:
ProtocolException- Thrown if the remote server sent an unexpected response, e.g. wrong status codes or missing/invalid headers.IOException- Thrown if an exception occurs while issuing the HTTP request.
-
prepareConnection
Set headers used for every HTTP request. Currently, this will add the Tus-Resumable header and any custom header which can be configured usingsetHeaders(Map),- Parameters:
connection- The connection whose headers will be modified.
-
uploadFinished
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
-