Android API Client

Android (Kotlin and Java) integration handles uploads and file operations by wrapping Uploadcare Upload API and REST API. This comprehensive API client lets you use most of the Uploadcare features from within your Android app. It also includes a native uploading widget.

GitHub →

Features

Concise and easy-to-use library without extra resources and drawables.

Uploading (Upload API):

  • Upload files from a file, byte array, URL, URI and cloud sources (up to 5 TB)
  • Multipart uploading for large files
  • Uploading network to speed uploading jobs (like CDN)

File uploading widget:

  • Upload files from a local disk, camera, and cloud sources
  • Track, pause and continue multipart uploading
  • Background uploading
  • Bulk file uploading
  • Material design Uploader appearance customization and styles

File management (REST API):

  • Get file info and perform various operations (store/delete/copy) with them
  • Work with groups of files
  • Get info about account project
  • Manage webhooks
  • Convert documents
  • Encode and transform videos
  • Paginated resource fetching
  • Synchronous and asynchronous operation modes

Image processing (URL API):

  • CDN path builder
  • Compression
  • Geometry
  • Colors
  • Definition
  • Image and text overlays
  • Rotations
  • Recognition
  • File info
  • Proxy (fetch)

Security:

  • Secure authentication
  • Secure uploads (signed uploads)
  • Secure delivery (signed URLs)

Installation from Maven Central

The latest stable versions are available at Maven Central.

To include API client and the uploading widget in your Android project, add this line to the ‘gradle.build’ file:

implementation 'com.uploadcare.android.library:uploadcare-android:4.3.1'
implementation 'com.uploadcare.android.widget:uploadcare-android-widget:4.3.1'

Initialization

REST API requires both public and secret keys. If you use Upload API only, you can specify just “YOUR_PUBLIC_KEY”. Get your Public and Secret API keys.

Kotlin

1val uploadcare = UploadcareClient("YOUR_PUBLIC_KEY", "YOUR_SECRET_KEY")

Java

1UploadcareClient uploadcare = new UploadcareClient("YOUR_PUBLIC_KEY", "YOUR_SECRET_KEY");

For uploading widget, place your Uploadcare public/private keys into ../res/strings.xml file:

1<resources>
2 <!--Replace with your public/secret keys to use UploadcareWidget. Private key is optional, required only if you use Rest API features.-->
3 <string name="uploadcare_public_key" translatable="false">place_uploadcare_public_key_here</string>
4 <string name="uploadcare_secret_key" translatable="false">place_uploadcare_secret_key_here</string>
5</resources>

Using REST API

You can use both synchronous and asynchronous operations.

Asynchronous file info fetch

Kotlin

1uploadcare.getFileAsync(
2 context, // Context
3 "YOUR_FILE_UUID", // File UUID
4 object : UploadcareFileCallback {
5 override fun onFailure(e: UploadcareApiException) {
6 // Handle errors.
7 }
8
9 override fun onSuccess(result: UploadcareFile) {
10 // Successfully fetched file.
11 }
12 })

Java

1uploadcare.getFileAsync(
2 context, // Context
3 "YOUR_FILE_UUID", // File UUID
4 new UploadcareFileCallback() {
5 @Override
6 public void onFailure(@NotNull UploadcareApiException e) {
7 // Handle errors.
8 }
9
10 @Override
11 public void onSuccess(@NonNull UploadcareFile result) {
12 // Successfully fetched file.
13 }
14 });

Synchronous file info fetch

Kotlin

1val file = uploadcare.getFile("YOUR_FILE_UUID")

Java

1UploadcareFile file = uploadcare.getFile("YOUR_FILE_UUID");

Find out more examples in the API client documentation for Android at GitHub.

Using Upload API

You can use both synchronous and asynchronous operations.

Asynchronous file upload

Kotlin

1val context = ...// Context
2val fileUri = ...//resource representing file (File/Uri/InputStream/ByteArray/String types are supported).
3val uploader = FileUploader(uploadcare, fileUri, context) // Use "MultipleFilesUploader" for multiple files.
4 .store(true)
5 // Other upload parameters.
6
7uploader.uploadAsync(object : UploadFileCallback {
8 override fun onFailure(e: UploadcareApiException) {
9 // Handle errors.
10 }
11
12 override fun onProgressUpdate(
13 bytesWritten: Long,
14 contentLength: Long,
15 progress: Double) {
16 // Upload progress info.
17 }
18
19 override fun onSuccess(result: UploadcareFile) {
20 // Successfully uploaded file to Uploadcare.
21 }
22})
23
24// Cancel upload in progress.
25uploader.cancel()

Java

1Context context = ...// Context
2Uri fileUri = ...//resource representing file (File/Uri/InputStream/ByteArray/String types are supported).
3Uploader uploader = new FileUploader(uploadcare, fileUri, context) // Use "MultipleFilesUploader" for multiple files.
4 .store(true);
5 // Other upload parameters.
6
7uploader.uploadAsync(new UploadFileCallback() {
8 @Override
9 public void onFailure(UploadcareApiException e) {
10 // Handle errors.
11 }
12
13 @Override
14 public void onProgressUpdate(
15 Long bytesWritten,
16 Long contentLength,
17 Double progress) {
18 // Upload progress info.
19 }
20
21 @Override
22 public void onSuccess(UploadcareFile file) {
23 // Successfully uploaded file to Uploadcare.
24 }
25});
26
27// Cancel upload in progress.
28uploader.cancel();

Synchronous file upload

Kotlin

1val context = ...// Context
2val fileUri = ...//resource representing file (File/Uri/InputStream/ByteArray/String types are supported).
3val uploader = FileUploader(uploadcare, fileUri, context) // Use "MultipleFilesUploader" for multiple files.
4 .store(true)
5 // Other upload parameters.
6
7try {
8 val file = uploader.upload()
9 // Successfully uploaded file to Uploadcare.
10} catch (e: UploadFailureException) {
11 // Handle errors.
12}

Java

1Context context = ...// Context
2Uri fileUri = ...//resource representing file (File/Uri/InputStream/ByteArray/String types are supported).
3Uploader uploader = new FileUploader(uploadcare, fileUri, context) // Use "MultipleFilesUploader" for multiple files.
4 .store(true);
5 // Other upload parameters.
6
7try {
8 UploadcareFile file = uploader.upload();
9 // Successfully uploaded file to Uploadcare.
10} catch (UploadFailureException e) {
11 // Handle errors.
12}

Find out more examples in the API client documentation for Android at GitHub.

Using uploading widget

You can select and upload file from any available local file, camera, external source, Activity/Fragment.

Kotlin

1// Register Activity Result Launcher
2val uploadcareLauncher = registerForActivityResult(UploadcareActivityResultContract) { result ->
3 result?.let {
4 //handle result.
5 }
6}
7
8// Launch UploadcareWidget
9val params = UploadcareWidgetParams() // set parameters for upload
10uploadcareLauncher.launch(params)

Java

1// Register Activity Result Launcher
2ActivityResultLauncher<UploadcareWidgetParams> uploadcareLauncher = registerForActivityResult(UploadcareActivityResultContract.INSTANCE, result -> {
3 if (result != null) {
4 // handle result.
5 }
6});
7
8// Launch UploadcareWidget
9UploadcareWidgetParams params = new UploadcareWidgetParams(); // set parameters for upload
10uploadcareLauncher.launch(params);

Find out more examples in the uploading widget documentation for Android at GitHub.

  • Integration with Java