Package me.desair.tus.server.upload
Interface UploadStorageService
- All Known Implementing Classes:
DiskStorageService,ThreadLocalCachedStorageAndLockingService
public interface UploadStorageService
Interface to a service that is able to store the (partially) uploaded files.
-
Method Summary
Modifier and TypeMethodDescriptionappend(UploadInfo upload, InputStream inputStream) Append the bytes in the giveInputStreamto the upload with the given ID starting at the provided offset.voidcleanupExpiredUploads(UploadLockingService uploadLockingService) Clean up any upload data that is expired according to the configured expiration time.voidcopyUploadTo(UploadInfo info, OutputStream outputStream) Copy the uploaded bytes to the given output stream.create(UploadInfo info, String ownerKey) Create an upload location with the given upload information.longGet the maximum upload size configured on this storage service.Return theUploadConcatenationServiceimplementation that this upload service is using.getUploadedBytes(String uploadUri, String ownerKey) Get the uploaded bytes corresponding to the given upload URL as a stream.Get the uploaded bytes corresponding to the given upload ID as a stream.Get the expiration period of an upload in milliseconds.getUploadInfo(String uploadUrl, String ownerKey) Method to retrieve the upload info by its upload URL.Method to retrieve the upload info by its ID.The URI which is configured as the upload endpoint.voidremoveLastNumberOfBytes(UploadInfo uploadInfo, long byteCount) Remove the given last amount of bytes from the uploaded data.voidsetIdFactory(UploadIdFactory idFactory) Set an instance if IdFactory to be used for creating identities and extracting them from uploadUris.voidsetMaxUploadSize(Long maxUploadSize) Limit the maximum upload size to the given value.voidsetUploadConcatenationService(UploadConcatenationService concatenationService) Set theUploadConcatenationServicethat this upload storage service should use.voidsetUploadExpirationPeriod(Long uploadExpirationPeriod) Set the expiration period after which an in-progress upload expires.voidterminateUpload(UploadInfo uploadInfo) Terminate completed and unfinished uploads allowing the Server to free up used resources.voidupdate(UploadInfo uploadInfo) Update the upload information for the provided ID.
-
Method Details
-
getUploadInfo
Method to retrieve the upload info by its upload URL.- Parameters:
uploadUrl- The URL corresponding to this upload. This parameter can be null.ownerKey- A key representing the owner of the upload- Returns:
- The upload info matching the given URL, or null when not found.
- Throws:
IOException
-
getUploadInfo
Method to retrieve the upload info by its ID.- Parameters:
id- The ID of the upload- Returns:
- The matching upload info
- Throws:
IOException- When the service is not able to retrieve the upload information
-
getUploadUri
String getUploadUri()The URI which is configured as the upload endpoint.- Returns:
- The URI
-
append
Append the bytes in the giveInputStreamto the upload with the given ID starting at the provided offset. This method also updates theUploadInfocorresponding to this upload. The Upload Storage server should not exceed its max upload size when writing bytes.- Parameters:
upload- The ID of the uploadinputStream- The input stream containing the bytes to append- Returns:
- The new
UploadInfofor this upload - Throws:
IOExceptionTusException
-
setMaxUploadSize
Limit the maximum upload size to the given value.- Parameters:
maxUploadSize- The maximum upload limit to set
-
getMaxUploadSize
long getMaxUploadSize()Get the maximum upload size configured on this storage service.- Returns:
- The maximum upload size or zero if no maximum
-
create
Create an upload location with the given upload information.- Parameters:
info- The Upload information to use to create the new uploadownerKey- A key representing the owner of the upload- Returns:
- An
UploadInfoobject containing the information used to create the upload and its unique ID - Throws:
IOException
-
update
Update the upload information for the provided ID.- Parameters:
uploadInfo- The upload info object containing the ID and information to update- Throws:
IOExceptionUploadNotFoundException
-
getUploadedBytes
InputStream getUploadedBytes(String uploadUri, String ownerKey) throws IOException, UploadNotFoundException Get the uploaded bytes corresponding to the given upload URL as a stream.- Parameters:
uploadUri- The URIownerKey- The owner key of this upload- Returns:
- an
OutputStreamcontaining the bytes of the upload - Throws:
IOExceptionUploadNotFoundException
-
getUploadedBytes
Get the uploaded bytes corresponding to the given upload ID as a stream.- Parameters:
id- the ID of the upload- Returns:
- an
OutputStreamcontaining the bytes of the upload - Throws:
IOException- When retrieving the bytes from the storage layer failsUploadNotFoundException- When the proved id is not linked to an upload
-
copyUploadTo
void copyUploadTo(UploadInfo info, OutputStream outputStream) throws UploadNotFoundException, IOException Copy the uploaded bytes to the given output stream.- Parameters:
info- The upload of which we should copy the bytesoutputStream- The output stream where we have to copy the bytes to- Throws:
UploadNotFoundExceptionIOException
-
cleanupExpiredUploads
Clean up any upload data that is expired according to the configured expiration time.- Parameters:
uploadLockingService- AnUploadLockingServicethat can be used to check and lock uploads- Throws:
IOException
-
removeLastNumberOfBytes
void removeLastNumberOfBytes(UploadInfo uploadInfo, long byteCount) throws UploadNotFoundException, IOException Remove the given last amount of bytes from the uploaded data.- Parameters:
uploadInfo- Upload of which to remove the bytesbyteCount- The number of bytes to remove at the end- Throws:
UploadNotFoundExceptionIOException
-
terminateUpload
Terminate completed and unfinished uploads allowing the Server to free up used resources.- Parameters:
uploadInfo- The upload to terminate- Throws:
UploadNotFoundExceptionIOException
-
getUploadExpirationPeriod
Long getUploadExpirationPeriod()Get the expiration period of an upload in milliseconds.- Returns:
- The number of milliseconds before an upload expires, or null if it cannot expire
-
setUploadExpirationPeriod
Set the expiration period after which an in-progress upload expires.- Parameters:
uploadExpirationPeriod- The period in milliseconds
-
setUploadConcatenationService
Set theUploadConcatenationServicethat this upload storage service should use.- Parameters:
concatenationService- The UploadConcatenationService implementation to use
-
getUploadConcatenationService
UploadConcatenationService getUploadConcatenationService()Return theUploadConcatenationServiceimplementation that this upload service is using.- Returns:
- The UploadConcatenationService that is being used
-
setIdFactory
Set an instance if IdFactory to be used for creating identities and extracting them from uploadUris.- Parameters:
idFactory- TheUploadIdFactoryto use within this storage service
-