{"id":18917779,"url":"https://github.com/tus/tus-java-client","last_synced_at":"2025-04-08T12:07:47.975Z","repository":{"id":35028832,"uuid":"39138763","full_name":"tus/tus-java-client","owner":"tus","description":"The tus client for Java.","archived":false,"fork":false,"pushed_at":"2025-03-17T11:50:22.000Z","size":1055,"stargazers_count":219,"open_issues_count":10,"forks_count":88,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-01T10:17:18.971Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://tus.io","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-15T13:37:28.000Z","updated_at":"2025-03-17T11:50:18.000Z","dependencies_parsed_at":"2023-11-06T09:45:16.081Z","dependency_job_id":"fa881c9d-fd79-49da-8c1d-8f46a12a0f28","html_url":"https://github.com/tus/tus-java-client","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tus%2Ftus-java-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tus%2Ftus-java-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tus%2Ftus-java-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tus%2Ftus-java-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tus","download_url":"https://codeload.github.com/tus/tus-java-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247838444,"owners_count":21004580,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T10:28:07.221Z","updated_at":"2025-04-08T12:07:47.949Z","avatar_url":"https://github.com/tus.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tus-java-client [![Tests](https://github.com/tus/tus-java-client/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/tus/tus-java-client/actions/workflows/tests.yml)\n\n\u003e **tus** is a protocol based on HTTP for *resumable file uploads*. Resumable\n\u003e means that an upload can be interrupted at any moment and can be resumed without\n\u003e re-uploading the previous data again. An interruption may happen willingly, if\n\u003e the user wants to pause, or by accident in case of a network issue or server\n\u003e outage.\n\n**tus-java-client** is a library for uploading files using the *tus* protocol to any remote server supporting it.\n\nThis library is also compatible with the Android platform and can be used without any modifications using the API. The [tus-android-client](https://github.com/tus/tus-android-client) provides additional classes which can be used in addition the Java library.\n\n## Usage\n\n```java\n// Create a new TusClient instance\nTusClient client = new TusClient();\n\n// Configure tus HTTP endpoint. This URL will be used for creating new uploads\n// using the Creation extension\nclient.setUploadCreationURL(new URL(\"https://tusd.tusdemo.net/files\"));\n\n// Enable resumable uploads by storing the upload URL in memory\nclient.enableResuming(new TusURLMemoryStore());\n\n// Open a file using which we will then create a TusUpload. If you do not have\n// a File object, you can manually construct a TusUpload using an InputStream.\n// See the documentation for more information.\nFile file = new File(\"./cute_kitten.png\");\nfinal TusUpload upload = new TusUpload(file);\n\nSystem.out.println(\"Starting upload...\");\n\n// We wrap our uploading code in the TusExecutor class which will automatically catch\n// exceptions and issue retries with small delays between them and take fully\n// advantage of tus' resumability to offer more reliability.\n// This step is optional but highly recommended.\nTusExecutor executor = new TusExecutor() {\n    @Override\n    protected void makeAttempt() throws ProtocolException, IOException {\n        // First try to resume an upload. If that's not possible we will create a new\n        // upload and get a TusUploader in return. This class is responsible for opening\n        // a connection to the remote server and doing the uploading.\n        TusUploader uploader = client.resumeOrCreateUpload(upload);\n        \n        // Alternatively, if your tus server does not support the Creation extension\n        // and you obtained an upload URL from another service, you can instruct\n        // tus-java-client to upload to a specific URL. Please note that this is usually\n        // _not_ necessary and only if the tus server does not support the Creation\n        // extension. The Vimeo API would be an example where this method is needed.\n        // TusUploader uploader = client.beginOrResumeUploadFromURL(upload, new URL(\"https://tus.server.net/files/my_file\"));\n\n        // Upload the file in chunks of 1KB sizes.\n        uploader.setChunkSize(1024);\n\n        // Upload the file as long as data is available. Once the\n        // file has been fully uploaded the method will return -1\n        do {\n            // Calculate the progress using the total size of the uploading file and\n            // the current offset.\n            long totalBytes = upload.getSize();\n            long bytesUploaded = uploader.getOffset();\n            double progress = (double) bytesUploaded / totalBytes * 100;\n\n            System.out.printf(\"Upload at %06.2f%%.\\n\", progress);\n        } while(uploader.uploadChunk() \u003e -1);\n\n        // Allow the HTTP connection to be closed and cleaned up\n        uploader.finish();\n\n        System.out.println(\"Upload finished.\");\n        System.out.format(\"Upload available at: %s\", uploader.getUploadURL().toString());\n    }\n};\nexecutor.makeAttempts();\n\n```\n\n## Installation\n\nThe JARs can be downloaded manually from our [Maven Central Repo](https://central.sonatype.com/namespace/io.tus.java.client).\n\n**Gradle:**\n\n```groovy\nimplementation 'io.tus.java.client:tus-java-client:0.5.0'\n```\n\n**Maven:**\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.tus.java.client\u003c/groupId\u003e\n  \u003cartifactId\u003etus-java-client\u003c/artifactId\u003e\n  \u003cversion\u003e0.5.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Documentation\n\nThe documentation of the latest versions can be found online at [javadoc.io](https://javadoc.io/doc/io.tus.java.client/tus-java-client).\n\n## FAQ\n\n### Can I use my own custom SSLSocketFactory?\n\nYes, you can! Create a subclass of `TusClient` and override the `prepareConnection` method to attach your `SSLSocketFactory`. After this use your custom `TusClient` subclass as you would normally use it. Here is an example:\n\n```java\n@Override\npublic void prepareConnection(@NotNull HttpURLConnection connection) {\n    super.prepareConnection(connection);\n    \n    if(connection instanceof HttpsURLConnection) {\n        HttpsURLConnection secureConnection = (HttpsURLConnection) connection;\n        secureConnection.setSSLSocketFactory(mySSLSocketFactory);\n    }\n}\n```\n\n### Can I use a proxy that will be used for uploading files?\n\nYes, just add a proxy to the TusClient as shown below (1 line added to the above [usage](#usage)):\n\n```java\nTusClient client = new TusClient();\nProxy myProxy = new Proxy(...);\nclient.setProxy(myProxy);\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftus%2Ftus-java-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftus%2Ftus-java-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftus%2Ftus-java-client/lists"}