Class UploadInfo

java.lang.Object
me.desair.tus.server.upload.UploadInfo
All Implemented Interfaces:
Serializable

public class UploadInfo extends Object implements 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

    Constructors
    Constructor
    Description
    Default constructor to use if an upload is created without HTTP request
    UploadInfo(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 Type
    Method
    Description
    boolean
     
    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 GMT
    Get 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 GMT
    Get 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 GMT
    Try to guess the mime-type of the uploaded data.
    Try to guess the filename of the uploaded data.
    Get the unique identifier of this upload process The unique identifier is represented by a UploadId instance
    Get 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 client
    Return the type of this upload.
    int
     
    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 expired
    boolean
    An upload is still in progress: - as long as we did not receive information on the total length (see getLength()) - the total length does not match the current offset
    void
    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 a UploadId instance
    void
    setLength(Long length)
    Set the total length of the byte array that the client wants to upload.
    void
    setOffset(Long offset)
    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 client
    void
    Set the type of this upload.
    void
    updateExpiration(long expirationPeriod)
    Calculate the expiration timestamp based on the provided expiration period.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • 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

      public Long 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

      public void setOffset(Long offset)
      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

      public String 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

      public void setEncodedMetadata(String encodedMetadata)
      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

      public Map<String,String> 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

      public Long 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

      public void setLength(Long length)
      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 (see getLength()) - the total length does not match the current offset
      Returns:
      true if the upload is still in progress, false otherwise
    • setId

      public void setId(UploadId id)
      Set the unique identifier of this upload process The unique identifier is represented by a UploadId instance
      Parameters:
      id - The unique identifier to use
    • getId

      public UploadId getId()
      Get the unique identifier of this upload process The unique identifier is represented by a UploadId instance
      Returns:
      The unique upload identifier of this upload
    • setOwnerKey

      public void setOwnerKey(String ownerKey)
      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

      public String 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

      public Long 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

      public Long 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

      public String 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

      public UploadType getUploadType()
      Return the type of this upload. An upload can have types specified in UploadType. 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

      public void setUploadType(UploadType uploadType)
      Set the type of this upload. An upload can have types specified in UploadType. 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

      public void setConcatenationPartIds(List<String> concatenationPartIds)
      Set the list of upload identifiers of which this upload is composed of.
      Parameters:
      concatenationPartIds - The list of child upload identifiers
    • getConcatenationPartIds

      public List<String> getConcatenationPartIds()
      Get the list of upload identifiers of which this upload is composed of.
      Returns:
      The list of child upload identifiers
    • setUploadConcatHeaderValue

      public void setUploadConcatHeaderValue(String uploadConcatHeaderValue)
      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

      public String 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

      public String 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

      public String 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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getCurrentTime

      protected long getCurrentTime()
      Get the current time in the number of milliseconds since January 1, 1970, 00:00:00 GMT