GitHub - terrischwartz/tus_servlet: java servlet implementing server side of tus file upload protocol (original) (raw)
#tus_servlet
Java servlet implementing server side of the TUS Protocol 1.0.0
Quick Start
Build and launch a standalone server at http://localhost:8080
Quick Upload
$ curl -X POST -I 'http://localhost:8080/files'
-H 'Tus-Resumable: 1.0.0'
-H 'Upload-Length: 12345678'
HTTP/1.1 201 Created Location: http://localhost:8080/files/70ede2c5_f139_4aeb_b2da_774149c68286 Tus-Resumable: 1.0.0 X-Content-Type-Options: nosniff Content-Length: 0 Server: Jetty(7.2.0.v20101020)
$ curl -X PATCH -I 'http://localhost:8080/files/70ede2c5_f139_4aeb_b2da_774149c68286'
-H 'Tus-Resumable: 1.0.0'
-H 'Upload-Offset: 0'
-H 'Content-Type: application/offset+octet-stream'
--upload-file path/to/file.mp4
HTTP/1.1 100 Continue
HTTP/1.1 204 No Content Upload-Offset: 2299 Tus-Resumable: 1.0.0 X-Content-Type-Options: nosniff Content-Length: 0 Server: Jetty(7.2.0.v20101020)
Upload using a javascript client
Get the client code
$ git clone https://github.com/tus/tus-js-client $ cd tus-js-client/demo $ ls demo.css demo.js index.html
Open index.html in a browser. In the form, set the upload endpoint to http://localhost:8080/files and use the Browse button to try out uploads. This servlet doesn't implement GET so downloads won't work.
Incorporate the Servlet in Your Application
Build a jar containing the servlet
$ mvn package
Install the jar in your local mvn repo
$ mvn install
Add the dependency to pom.xml
org.tus tus_servlet 0.1-SNAPSHOT com.fasterxml.jackson.core jackson-core 2.6.3 com.fasterxml.jackson.core jackson-databind 2.6.3 com.fasterxml.jackson.core jackson-annotations 2.6.3 org.slf4j slf4j-api 1.7.5 org.slf4j slf4j-log4j12 1.7.5Add the filter and servlet to web.xml
<filter>
<filter-name>MethodOverrideFilter</filter-name>
<filter-class>org.tus.filter.methodoverride.HttpMethodOverrideFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MethodOverrideFilter</filter-name>
<servlet-name>upload</servlet-name>
</filter-mapping>
<servlet>
<servlet-name>upload</servlet-name>
<servlet-class> org.tus.servlet.upload.Upload </servlet-class>
<!-- More info about init-params below -->
<init-param>
<param-name>uploadFolder</param-name>
<param-value>/tmp</param-value>
</init-param>
<init-param>
<param-name>maxFileSize</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>maxStorage</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>upload</servlet-name>
<url-pattern>/files/*</url-pattern>
</servlet-mapping>
If using the servlet in a struts app, you'll need to configure struts.xml to ignore the path that this servlet is handling. For example:
<constant name="struts.action.excludePattern" value="/files,/files/[0-9a-zA-Z_]*"/>
Configuration (web.xml init-param)
- uploadFolder - Absolute pathname of the directory to which files will be uploaded. Directory must already exist.
- maxFileSize - Maxiumum number of bytes allowed for a single file. 0 means unlimited.
- maxStorage - Maximum number of bytes this servlet will use for uploaded files. 0 means unlimited. NOT IMPLEMENTED.
- maxRequest - Maximum number of bytes server will accept in a single patch request. 0 means unlimited.