Package me.desair.tus.server.upload
Class UploadInfo
java.lang.Object
me.desair.tus.server.upload.UploadInfo
- All Implemented Interfaces:
Serializable
Class that contains all metadata on an upload process. This class also holds the metadata
provided by the client when creating the upload.
- See Also:
-
Constructor Summary
ConstructorDescriptionDefault constructor to use if an upload is created without HTTP requestUploadInfo
(jakarta.servlet.http.HttpServletRequest servletRequest) Constructor to use if the upload is created using an HTTP request (which is usually the case) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Get the list of upload identifiers of which this upload is composed of.The timestamp this upload was created in number of milliseconds since January 1, 1970, 00:00:00 GMTGet the ip-addresses that were involved when this upload was created.protected long
Get the current time in the number of milliseconds since January 1, 1970, 00:00:00 GMTGet the encoded Tus metadata string as it was provided by the Tus client at creation of the upload.Indicates the timestamp after which the upload expires in milliseconds since January 1, 1970, 00:00:00 GMTTry to guess the mime-type of the uploaded data.Try to guess the filename of the uploaded data.getId()
Get the unique identifier of this upload process The unique identifier is represented by aUploadId
instanceGet the total length of the byte array that the client wants to upload.Get the decoded metadata map provided by the client based on the encoded Tus metadata string received on creation of the upload.The current byte offset of the bytes that already have been stored for this upload on the server.Get the owner key for this upload.Get the original value of the "Upload-Concat" HTTP header that was provided by the clientReturn the type of this upload.int
hashCode()
boolean
Did the client already provide a total upload length?boolean
Did the client provide any metadata when creating this upload?boolean
Check if this upload is expiredboolean
An upload is still in progress: - as long as we did not receive information on the total length (seegetLength()
) - the total length does not match the current offsetvoid
setConcatenationPartIds
(List<String> concatenationPartIds) Set the list of upload identifiers of which this upload is composed of.void
setEncodedMetadata
(String encodedMetadata) Set the encoded Tus metadata string as it was provided by the Tus client at creation of the upload.void
Set the unique identifier of this upload process The unique identifier is represented by aUploadId
instancevoid
Set the total length of the byte array that the client wants to upload.void
Set the position where the next newly received byte should be stored.void
setOwnerKey
(String ownerKey) Set the owner key for this upload.void
setUploadConcatHeaderValue
(String uploadConcatHeaderValue) Set the original value of the "Upload-Concat" HTTP header that was provided by the clientvoid
setUploadType
(UploadType uploadType) Set the type of this upload.void
updateExpiration
(long expirationPeriod) Calculate the expiration timestamp based on the provided expiration period.
-
Constructor Details
-
UploadInfo
public UploadInfo()Default constructor to use if an upload is created without HTTP request -
UploadInfo
public UploadInfo(jakarta.servlet.http.HttpServletRequest servletRequest) Constructor to use if the upload is created using an HTTP request (which is usually the case)- Parameters:
servletRequest
- The HTTP request that creates the new upload
-
-
Method Details
-
getOffset
The current byte offset of the bytes that already have been stored for this upload on the server. The offset is the position where the next newly received byte should be stored. This index is zero-based.- Returns:
- The offset where the next new byte will be written
-
setOffset
Set the position where the next newly received byte should be stored. This index is zero-based.- Parameters:
offset
- The offset where the next new byte should be written
-
getEncodedMetadata
Get the encoded Tus metadata string as it was provided by the Tus client at creation of the upload. The encoded metadata string consists of one or more comma-separated key-value pairs where the key is ASCII encoded and the value Base64 encoded. See https://tus.io/protocols/resumable-upload.html#upload-metadata- Returns:
- The encoded metadata string as received from the client
-
setEncodedMetadata
Set the encoded Tus metadata string as it was provided by the Tus client at creation of the upload. The encoded metadata string consists of one or more comma-separated key-value pairs where the key is ASCII encoded and the value Base64 encoded. See https://tus.io/protocols/resumable-upload.html#upload-metadata -
getMetadata
Get the decoded metadata map provided by the client based on the encoded Tus metadata string received on creation of the upload. The encoded metadata string consists of one or more comma-separated key-value pairs where the key is ASCII encoded and the value Base64 encoded. The key and value MUST be separated by a space. See https://tus.io/protocols/resumable-upload.html#upload-metadata- Returns:
- The encoded metadata string as received from the client
-
hasMetadata
public boolean hasMetadata()Did the client provide any metadata when creating this upload?- Returns:
- True if metadata is present, false otherwise
-
getLength
Get the total length of the byte array that the client wants to upload. This value is provided by the client when creating the upload (POST) or when uploading a new set of bytes (PATCH).- Returns:
- The number of bytes that the client specified he will upload
-
setLength
Set the total length of the byte array that the client wants to upload. The client can provided this value when creating the upload (POST) or when uploading a new set of bytes (PATCH).- Parameters:
length
- The number of bytes that the client specified he will upload
-
hasLength
public boolean hasLength()Did the client already provide a total upload length?- Returns:
- True if the total upload length is known, false otherwise
-
isUploadInProgress
public boolean isUploadInProgress()An upload is still in progress: - as long as we did not receive information on the total length (seegetLength()
) - the total length does not match the current offset- Returns:
- true if the upload is still in progress, false otherwise
-
setId
Set the unique identifier of this upload process The unique identifier is represented by aUploadId
instance- Parameters:
id
- The unique identifier to use
-
getId
Get the unique identifier of this upload process The unique identifier is represented by aUploadId
instance- Returns:
- The unique upload identifier of this upload
-
setOwnerKey
Set the owner key for this upload. This key uniquely identifies the owner of the uploaded bytes. The user of this library is free to interpret the meaning of "owner". This can be a user ID, a company division, a group of users, a tenant...- Parameters:
ownerKey
- The owner key to assign to this upload
-
getOwnerKey
Get the owner key for this upload. This key uniquely identifies the owner of the uploaded bytes. The user of this library is free to interpret the meaning of "owner". This can be a user ID, a company division, a group of users, a tenant...- Returns:
- The unique identifying key of the owner of this upload
-
getExpirationTimestamp
Indicates the timestamp after which the upload expires in milliseconds since January 1, 1970, 00:00:00 GMT- Returns:
- The expiration timestamp in milliseconds
-
updateExpiration
public void updateExpiration(long expirationPeriod) Calculate the expiration timestamp based on the provided expiration period.- Parameters:
expirationPeriod
- The period the upload should remain valid
-
getCreationTimestamp
The timestamp this upload was created in number of milliseconds since January 1, 1970, 00:00:00 GMT- Returns:
- Creation timestamp of this upload object
-
getCreatorIpAddresses
Get the ip-addresses that were involved when this upload was created. The returned value is a comma-separated list based on the remote address of the request and the X-Forwareded-For header. The list is constructed as "client, proxy1, proxy2".- Returns:
- A comma-separated list of ip-addresses
-
getUploadType
Return the type of this upload. An upload can have types specified inUploadType
. The type of an upload depends on the Tus concatenation extension: https://tus.io/protocols/resumable-upload.html#concatenation- Returns:
- The type of this upload as specified in
UploadType
-
setUploadType
Set the type of this upload. An upload can have types specified inUploadType
. The type of an upload depends on the Tus concatenation extension: https://tus.io/protocols/resumable-upload.html#concatenation- Parameters:
uploadType
- The type to set on this upload
-
setConcatenationPartIds
Set the list of upload identifiers of which this upload is composed of.- Parameters:
concatenationPartIds
- The list of child upload identifiers
-
getConcatenationPartIds
Get the list of upload identifiers of which this upload is composed of.- Returns:
- The list of child upload identifiers
-
setUploadConcatHeaderValue
Set the original value of the "Upload-Concat" HTTP header that was provided by the client- Parameters:
uploadConcatHeaderValue
- The original value of the "Upload-Concat" HTTP header
-
getUploadConcatHeaderValue
Get the original value of the "Upload-Concat" HTTP header that was provided by the client- Returns:
- The original value of the "Upload-Concat" HTTP header
-
getFileName
Try to guess the filename of the uploaded data. If we cannot guess the name we fall back to the ID.
NOTE: This is only a guess, there are no guarantees that the return value is correct- Returns:
- A potential file name
-
getFileMimeType
Try to guess the mime-type of the uploaded data.
NOTE: This is only a guess, there are no guarantees that the return value is correct- Returns:
- A potential file name
-
isExpired
public boolean isExpired()Check if this upload is expired- Returns:
- True if the upload is expired, false otherwise
-
equals
-
hashCode
public int hashCode() -
getCurrentTime
protected long getCurrentTime()Get the current time in the number of milliseconds since January 1, 1970, 00:00:00 GMT
-