Skip to content

Commit 5636b81

Browse files
committed
Add README
1 parent 8e795f6 commit 5636b81

File tree

1 file changed

+85
-3
lines changed

1 file changed

+85
-3
lines changed

README.md

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,86 @@
1-
tus-android-client
2-
==================
1+
# tus-android-client
32

4-
The tus client for android.
3+
> **tus** is a protocol based on HTTP for *resumable file uploads*. Resumable
4+
> means that an upload can be interrupted at any moment and can be resumed without
5+
> re-uploading the previous data again. An interruption may happen willingly, if
6+
> the user wants to pause, or by accident in case of an network issue or server
7+
> outage.
8+
9+
**tus-android-client** is a library meant to be used in addition to [tus-java-client](https://github.com/tus/tus-java-client) for uploading files using the *tus* protocol to any remote server supporting it. This package provides additional classes which makes interacting with the Java library easier on Android.
10+
11+
## Usage
12+
13+
```java
14+
// This example consumes the tus-java-client and tus-android-client libraries
15+
import io.tus.android.client.TusPreferencesURLStore;
16+
import io.tus.java.client.TusClient;
17+
import io.tus.java.client.TusUpload;
18+
import io.tus.java.client.TusUploader;
19+
20+
// Create a new TusClient instance
21+
TusClient client = new TusClient();
22+
23+
// Configure tus HTTP endpoint. This URL will be used for creating new uploads
24+
// using the Creation extension
25+
client.setUploadCreationURL(new URL("http://master.tus.io/files"));
26+
27+
// Enable resumable uploads by storing the upload URL in the preferences
28+
// and preserve them after app restarts
29+
SharedPreferences pref = getSharedPreferences("tus", 0);
30+
client.enableResuming(new TusPreferencesURLStore(pref));
31+
32+
// Open a file using which we will then create a TusUpload. If you do not have
33+
// a File object, you can manually construct a TusUpload using an InputStream.
34+
// See the documentation for more information.
35+
File file = new File("./cute_kitten.png");
36+
TusUpload upload = new TusUpload(file);
37+
38+
// First try to resume an upload. If that's not possible we will create a new
39+
// upload and get a TusUploader in return. This class is responsible for opening
40+
// a connection to the remote server and doing the uploading.
41+
TusUploader uploader = client.resumeOrCreateUpload(upload);
42+
43+
// Upload the file in chunks of 1KB as long as data is available. Once the
44+
// file has been fully uploaded the method will return -1
45+
while(uploader.uploadChunk(1024 * 1024) > -1) {
46+
// Calculate the progress using the total size of the uploading file and
47+
// the current offset.
48+
long totalBytes = upload.getSize();
49+
long bytesUploaded = uploader.getOffset();
50+
double progress = (double) bytesUploaded / totalBytes * 100;
51+
}
52+
53+
// Allow the HTTP connection to be closed and cleaned up
54+
uploader.finish();
55+
56+
```
57+
58+
The [example application](/example/src/main/java/io/tus/android/example/MainActivity.java) provides a more complete example in terms of interacting with the Android platform.
59+
60+
## Installation
61+
62+
The JARs can be downloaded manually from our [Bintray project](https://bintray.com/tus/maven/tus-android-client/view#files). tus-java-client is also available in JCenter (Maven Central is coming soon).
63+
64+
**Gradle:**
65+
66+
```groovy
67+
compile 'io.tus.android.client:tus-android-client:0.1.0'
68+
```
69+
70+
**Maven:**
71+
72+
```xml
73+
<dependency>
74+
<groupId>io.tus.android.client</groupId>
75+
<artifactId>tus-android-client</artifactId>
76+
<version>0.1.0</version>
77+
</dependency>
78+
```
79+
80+
## Documentation
81+
82+
The documentation of the latest version (master branch of git repository) can be found online at [tus.github.io/tus-android-client/javadoc/](https://tus.github.io/tus-android-client/javadoc/).
83+
84+
## License
85+
86+
MIT

0 commit comments

Comments
 (0)