All Projects → tomdesair → Tus Java Server

tomdesair / Tus Java Server

Licence: mit
Library to receive tus v1.0.0 file uploads in a Java server environment

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Tus Java Server

Fileup
FileUp - JQuery File Upload
Stars: ✭ 10 (-84.37%)
Mutual labels:  library, upload, file-upload
Xsbt Web Plugin
Servlet support for sbt
Stars: ✭ 381 (+495.31%)
Mutual labels:  servlet, tomcat, jetty
Pomf
Simple file uploading and sharing
Stars: ✭ 535 (+735.94%)
Mutual labels:  upload, file-upload
Cj Upload
Higher order React components for file uploading (with progress) react file upload
Stars: ✭ 589 (+820.31%)
Mutual labels:  upload, file-upload
Joinfaces Maven Jar Example
JoinFaces Maven Jar Example
Stars: ✭ 62 (-3.12%)
Mutual labels:  tomcat, jetty
Javalin
A simple and modern Java and Kotlin web framework
Stars: ✭ 5,184 (+8000%)
Mutual labels:  servlet, jetty
Pmhttp
Swift/Obj-C HTTP framework with a focus on REST and JSON
Stars: ✭ 509 (+695.31%)
Mutual labels:  rest, library
Restinio
Cross-platform, efficient, customizable, and robust asynchronous HTTP/WebSocket server C++14 library with the right balance between performance and ease of use
Stars: ✭ 694 (+984.38%)
Mutual labels:  rest, library
React Uploady
Modern file uploading - components & hooks for React
Stars: ✭ 372 (+481.25%)
Mutual labels:  upload, file-upload
Restless
Express.js api, type safe validations and more
Stars: ✭ 32 (-50%)
Mutual labels:  rest, library
Meteor Files
🚀 Upload files via DDP or HTTP to ☄️ Meteor server FS, AWS, GridFS, DropBox or Google Drive. Fast, secure and robust.
Stars: ✭ 1,033 (+1514.06%)
Mutual labels:  upload, file-upload
Instapy Cli
✨ Python library and CLI to upload photo and video on Instagram. W/o a phone!
Stars: ✭ 498 (+678.13%)
Mutual labels:  library, upload
Web
适合java新手入门练习的java web个人网站项目,目前主要维护web-mysql和web-psql两个分支。前台包括博客、代码库、文件下载、留言、登录注册、站内搜索、分类目录等功能,后台包括上传文件、博客、代码,编辑、删除文章,修改个人资料等功能,目前暂停开发新功能。网址:https://demo.hemingsheng.cn ,觉得不错的欢迎 star。 手机版网址:
Stars: ✭ 414 (+546.88%)
Mutual labels:  servlet, tomcat
Jikan
Unofficial MyAnimeList PHP+REST API which provides functions other than the official API
Stars: ✭ 531 (+729.69%)
Mutual labels:  rest, library
Dropwizard
A damn simple library for building production-ready RESTful web services.
Stars: ✭ 8,078 (+12521.88%)
Mutual labels:  rest, jetty
Chibisafe
Blazing fast file uploader and awesome bunker written in node! 🚀
Stars: ✭ 657 (+926.56%)
Mutual labels:  upload, file-upload
Phpmussel
PHP-based anti-virus anti-trojan anti-malware solution.
Stars: ✭ 337 (+426.56%)
Mutual labels:  upload, file-upload
Cppwebframework
​The C++ Web Framework (CWF) is a MVC web framework, Open Source, under MIT License, using C++ with Qt to be used in the development of web applications.
Stars: ✭ 348 (+443.75%)
Mutual labels:  rest, servlet
Warbler
Warbler chirpily constructs .war files of your Ruby applications.
Stars: ✭ 850 (+1228.13%)
Mutual labels:  servlet, tomcat
Linx Server
Self-hosted file/code/media sharing website. ~~~~~~~~~~~~~~~~~~~ Demo: https://demo.linx-server.net/
Stars: ✭ 1,044 (+1531.25%)
Mutual labels:  upload, file-upload

Build Status Test Coverage Codacy Badge Bugs Vulnerabilities Duplicated Lines

tus-java-server

This library can be used to enable resumable (and potentially asynchronous) file uploads in any Java web application. This allows the users of your application to upload large files over slow and unreliable internet connections. The ability to pause or resume a file upload (after a connection loss or reset) is achieved by implementing the open file upload protocol tus (https://tus.io/). This library implements the server-side of the tus v1.0.0 protocol with all optional extensions.

The Javadoc of this library can be found at https://tus.desair.me/. The following Java versions are supported: 7, 8, 9, 10 and 11.

Quick Start and Examples

The tus-java-server library only depends on Java Servlet API 3.1 and some Apache Commons utility libraries. This means that (in theory) you can use this library on any modern Java Web Application server like Tomcat, JBoss, Jetty... By default all uploaded data and information is stored on the file system of the application server (and currently this is the only option, see configuration section).

You can add the latest stable version of this library to your application using Maven by adding the following dependency:

<dependency>
  <groupId>me.desair.tus</groupId>
  <artifactId>tus-java-server</artifactId>
  <version>1.0.0-2.0</version>
</dependency>

The main entry point of the library is the me.desair.tus.server.TusFileUploadService.process(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) method. You can call this method inside a javax.servlet.http.HttpServlet, a javax.servlet.Filter or any REST API controller of a framework that gives you access to HttpServletRequest and HttpServletResponse objects. In the following list, you can find some example implementations:

Tus Protocol Extensions

Besides the core protocol, the library has all optional tus protocol extensions enabled by default. This means that the Tus-Extension header has value creation,creation-defer-length,checksum,checksum-trailer,termination,expiration,concatenation,concatenation-unfinished. Optionally you can also enable an unofficial download extension (see configuration section).

  • creation: The creation extension allows you to create new uploads and to retrieve the upload URL for them.
  • creation-defer-length: You can create a new upload even if you don't know its final length at the time of creation.
  • checksum: An extension that allows you to verify data integrity of each upload (PATCH) request.
  • checksum-trailer: If the checksum hash cannot be calculated at the beginning of the upload, it may be included as a trailer HTTP header at the end of the chunked HTTP request.
  • termination: Clients can terminate completed or in-progress uploads which allows the tus-java-server library to free up resources on the server.
  • expiration: You can instruct the tus-java-server library to cleanup uploads that are older than a configurable period.
  • concatenation: This extension can be used to concatenate multiple uploads into a single final upload enabling clients to perform parallel uploads and to upload non-contiguous chunks.
  • concatenation-unfinished: The client is allowed send the request to concatenate partial uploads while these partial uploads are still in progress.
  • download: The (unofficial) download extension allows clients to download uploaded files using a HTTP GET request. You can enable this extension by calling the withDownloadFeature() method.

Usage and Configuration

1. Setup

The first step is to create a TusFileUploadService object using its constructor. You can make this object available as a (Spring bean) singleton or create a new instance for each request. After creating the object, you can configure it using the following methods:

  • withUploadURI(String): Set the relative URL under which the main tus upload endpoint will be made available, for example /files/upload. Optionally, this URI may contain regex parameters in order to support endpoints that contain URL parameters, for example /users/[0-9]+/files/upload.
  • withMaxUploadSize(Long): Specify the maximum number of bytes that can be uploaded per upload. If you don't call this method, the maximum number of bytes is Long.MAX_VALUE.
  • withStoragePath(String): If you're using the default file system-based storage service, you can use this method to specify the path where to store the uploaded bytes and upload information.
  • withChunkedTransferDecoding: You can enable or disable the decoding of chunked HTTP requests by this library. Enable this feature in case the web container in which this service is running does not decode chunked transfers itself. By default, chunked decoding via this library is disabled (as modern frameworks tend to already do this for you).
  • withThreadLocalCache(Boolean): Optionally you can enable (or disable) an in-memory (thread local) cache of upload request data to reduce load on the storage backend and potentially increase performance when processing upload requests.
  • withUploadExpirationPeriod(Long): You can set the number of milliseconds after which an upload is considered as expired and available for cleanup.
  • withDownloadFeature(): Enable the unofficial download extension that also allows you to download uploaded bytes.
  • addTusExtension(TusExtension): Add a custom (application-specific) extension that implements the me.desair.tus.server.TusExtension interface. For example you can add your own extension that checks authentication and authorization policies within your application for the user doing the upload.
  • disableTusExtension(String): Disable the TusExtension for which the getName() method matches the provided string. The default extensions have names "creation", "checksum", "expiration", "concatenation", "termination" and "download". You cannot disable the "core" feature.
  • withUploadIdFactory(UploadIdFactory): Provide a custom UploadIdFactory implementation that should be used to generate identifiers for the different uploads. The default implementation generates identifiers using a UUID (UUIDUploadIdFactory). Another example implementation of a custom ID factory is the system-time based TimeBasedUploadIdFactory class.

For now this library only provides filesystem based storage and locking options. You can however provide your own implementation of a UploadStorageService and UploadLockingService using the methods withUploadStorageService(UploadStorageService) and withUploadLockingService(UploadLockingService) in order to support different types of upload storage.

2. Processing an upload

To process an upload request you have to pass the current javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse objects to the me.desair.tus.server.TusFileUploadService.process() method. Typical places were you can do this are inside Servlets, Filters or REST API Controllers (see examples).

Optionally you can also pass a String ownerKey parameter. The ownerKey can be used to have a hard separation between uploads of different users, groups or tenants in a multi-tenant setup. Examples of ownerKey values are user ID's, group names, client ID's...

3. Retrieving the uploaded bytes and metadata within the application

Once the upload has been completed by the user, the business logic layer of your application needs to retrieve and do something with the uploaded bytes. For example it could read the contents of the file, or move the uploaded bytes to their final persistent storage location. Retrieving the uploaded bytes in the backend can be achieved by using the me.desair.tus.server.TusFileUploadService.getUploadedBytes(String uploadURL) method. The passed uploadURL value should be the upload url used by the client to which the file was uploaded. Therefor your application should pass the upload URL of completed uploads to the backend. Optionally, you can also pass an ownerKey value to this method in case your application chooses to process uploads using owner keys. Examples of values that can be used as an ownerKey are: an internal user identifier, a session ID, the name of the subpart of your application...

Using the me.desair.tus.server.TusFileUploadService.getUploadInfo(String uploadURL) method you can retrieve metadata about a specific upload process. This includes metadata provided by the client as well as metadata kept by the library like creation timestamp, creator ip-address list, upload length... The method UploadInfo.getId() will return the unique identifier of this upload encapsulated in an UploadId instance. The original (custom generated) identifier object of this upload can be retrieved using UploadId.getOriginalObject(). A URL safe string representation of the identifier is returned by UploadId.toString(). It is highly recommended to consult the JavaDoc of both classes.

4. Upload cleanup

After having processed the uploaded bytes on the server backend (e.g. copy them to their final persistent location), it's important to cleanup the (temporary) uploaded bytes. This can be done by calling the me.desair.tus.server.TusFileUploadService.deleteUpload(String uploadURI) method. This will remove the uploaded bytes and any associated upload information from the storage backend. Alternatively, a client can also remove an (in-progress) upload using the termination extension.

Next to removing uploads after they have been completed and processed by the backend, it is also recommended to schedule a regular maintenance task to clean up any expired uploads or locks. Cleaning up expired uploads and locks can be achieved using the me.desair.tus.server.TusFileUploadService.cleanup() method.

Compatible Client Implementations

This tus protocol implementation has been tested with the Uppy file upload client. This repository also contains many automated integration tests that validate the tus protocol server implementation using plain HTTP requests. So in theory this means we're compatible with any tus 1.0.0 compliant client.

Versioning

This artifact is versioned as A.B.C-X.Y where A.B.C is the version of the implemented tus protocol (currently 1.0.0) and X.Y is the version of this library.

Contributing

This library comes without any warranty and is released under a MIT license. If you encounter any bugs or if you have an idea for a useful improvement you are welcome to open a new issue or to create a pull request with the proposed implementation. Please note that any contributed code needs to be accompanied by automated unit and/or integration tests and comply with the defined code-style.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].