public class TusClient
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
TUS_VERSION
Version of the tus protocol used by the client.
|
Constructor and Description |
---|
TusClient()
Create a new tus client.
|
Modifier and Type | Method and Description |
---|---|
TusUploader |
beginOrResumeUploadFromURL(TusUpload upload,
java.net.URL uploadURL)
Begin an upload or alternatively resume it if the upload has already been started before.
|
TusUploader |
createUpload(TusUpload upload)
Create a new upload using the Creation extension.
|
void |
disableRemoveFingerprintOnSuccess()
Disable removing fingerprints after a successful upload.
|
void |
disableResuming()
Disable resuming started uploads.
|
void |
enableRemoveFingerprintOnSuccess()
Enable removing fingerprints after a successful upload.
|
void |
enableResuming(TusURLStore urlStore)
Enable resuming already started uploads.
|
int |
getConnectTimeout()
Returns the Connection Timeout.
|
java.util.Map<java.lang.String,java.lang.String> |
getHeaders()
Get the HTTP headers which should be contained in every request and were configured using
setHeaders(Map) . |
java.net.URL |
getUploadCreationURL()
Get the current upload creation URL.
|
void |
prepareConnection(java.net.HttpURLConnection connection)
Set headers used for every HTTP request.
|
boolean |
removeFingerprintOnSuccessEnabled()
Get the current status if removing fingerprints after a successful upload.
|
TusUploader |
resumeOrCreateUpload(TusUpload upload)
Try to resume an upload using
resumeUpload(TusUpload) . |
TusUploader |
resumeUpload(TusUpload upload)
Try to resume an already started upload.
|
boolean |
resumingEnabled()
Get the current status if resuming.
|
void |
setConnectTimeout(int timeout)
Sets the timeout for a Connection.
|
void |
setHeaders(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.
|
void |
setUploadCreationURL(java.net.URL uploadCreationURL)
Set the URL used for creating new uploads.
|
protected void |
uploadFinished(TusUpload upload)
Actions to be performed after a successful upload completion.
|
public static final java.lang.String TUS_VERSION
public void setUploadCreationURL(java.net.URL uploadCreationURL)
createUpload(io.tus.java.client.TusUpload)
or resumeOrCreateUpload(io.tus.java.client.TusUpload)
but is not used if you
only resume existing uploads.uploadCreationURL
- Absolute upload creation URLpublic java.net.URL getUploadCreationURL()
public void enableResuming(@NotNull TusURLStore urlStore)
resumeUpload(TusUpload)
.urlStore
- Storage used to save and retrieve upload URLs by its fingerprint.public void disableResuming()
enableResuming(TusURLStore)
public boolean resumingEnabled()
enableResuming(TusURLStore)
enableResuming(TusURLStore)
,
disableResuming()
public void enableRemoveFingerprintOnSuccess()
disableRemoveFingerprintOnSuccess()
public void disableRemoveFingerprintOnSuccess()
enableRemoveFingerprintOnSuccess()
public boolean removeFingerprintOnSuccessEnabled()
enableResuming(TusURLStore)
enableRemoveFingerprintOnSuccess()
,
disableRemoveFingerprintOnSuccess()
public void setHeaders(@Nullable java.util.Map<java.lang.String,java.lang.String> headers)
headers
- The map of HTTP headersgetHeaders()
,
prepareConnection(HttpURLConnection)
@Nullable public java.util.Map<java.lang.String,java.lang.String> getHeaders()
setHeaders(Map)
.setHeaders(Map)
,
prepareConnection(HttpURLConnection)
public void setConnectTimeout(int timeout)
timeout
- in millisecondspublic int getConnectTimeout()
public TusUploader createUpload(@NotNull TusUpload upload) throws ProtocolException, java.io.IOException
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.upload
- The file for which a new upload will be createdTusUploader
to upload the file's chunks.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.public TusUploader resumeUpload(@NotNull TusUpload upload) throws FingerprintNotFoundException, ResumingNotEnabledException, ProtocolException, java.io.IOException
enableResuming(TusURLStore)
. This method will look up the URL for this
upload in the TusURLStore
using the upload's fingerprint (see
TusUpload.getFingerprint()
). After a successful lookup a HEAD request will be issued
to find the current offset without uploading the file, yet.upload
- The file for which an upload will be resumedTusUploader
to upload the remaining file's chunks.FingerprintNotFoundException
- Thrown if no matching fingerprint has been found in
TusURLStore
. Use createUpload(TusUpload)
to create a new upload.ResumingNotEnabledException
- Throw if resuming has not been enabled using enableResuming(TusURLStore)
.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.public TusUploader beginOrResumeUploadFromURL(@NotNull TusUpload upload, @NotNull java.net.URL uploadURL) throws ProtocolException, java.io.IOException
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.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.TusUploader
to upload the remaining file's chunks.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.public TusUploader resumeOrCreateUpload(@NotNull TusUpload upload) throws ProtocolException, java.io.IOException
resumeUpload(TusUpload)
. If the method call throws
an ResumingNotEnabledException
or FingerprintNotFoundException
, a new upload
will be created using createUpload(TusUpload)
.upload
- The file for which an upload will be resumedTusUploader
instance.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.public void prepareConnection(@NotNull java.net.HttpURLConnection connection)
setHeaders(Map)
,connection
- The connection whose headers will be modified.protected void uploadFinished(@NotNull TusUpload upload)
upload
- that has been finished