Quick Start - Get Started with Compression API in 5 Minutes
With just a few simple steps, you can integrate the SmartSlim Compression API service and make your first compression request using curl / Python / Java / Node.js
Step 1: Register an Account and Get Your API Key
Before calling the Compression API, you need to register a UGLYPEAR DATA account and create an application to obtain your API Key
Register at the Console
Visit the UGLYPEAR DATA Developer Console, register an account using your email or phone number, and complete identity verification to start using the service.
Create an Application
After logging into the console, create a new application in "Application Management", fill in the application name and purpose description, and select the desired service plan.
Get Your API Key
Once the application is created, the system will generate a unique API Key for it. Please keep it secure and do not expose it in client-side code or public repositories.
Security Tip: Your API Key is equivalent to your account credentials. Please read it through environment variables or a key management service. Never hardcode it in source code or commit it to code repositories.
Step 2: First API Call (curl)
After obtaining your API Key, use curl to quickly make a compression request and verify connectivity and service availability
curl -X POST https://api.uglypear.com/v1/compress \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F "file=@document.pdf" \
-F "quality=high"
Replace YOUR_API_KEY in the request with your actual API Key, file=@document.pdf points to the local file to compress, and the quality parameter can be low / medium / high.
Step 3: Python Example Code
Use the Python requests library to upload files and get compression results, suitable for backend service integration and data processing scripts
import requests
url = "https://api.uglypear.com/v1/compress"
headers = {"Authorization": "Bearer YOUR_API_KEY"}
files = {"file": open("document.pdf", "rb")}
data = {"quality": "high", "format": "pdf"}
response = requests.post(url, headers=headers, files=files, data=data)
result = response.json()
print(f"Compression complete, download link: {result['download_url']}")
Step 4: Node.js Example Code
Use Node.js with form-data and fetch to upload files, suitable for server-side Node applications and Serverless scenarios
const FormData = require('form-data');
const fs = require('fs');
const form = new FormData();
form.append('file', fs.createReadStream('document.pdf'));
form.append('quality', 'high');
fetch('https://api.uglypear.com/v1/compress', {
method: 'POST',
headers: { 'Authorization': 'Bearer YOUR_API_KEY', ...form.getHeaders() },
body: form
}).then(res => res.json()).then(data => console.log(data));
Step 5: Java Example Code (OkHttp)
Use Java OkHttp client to build a multipart request, suitable for enterprise-level Java backend and Android application integration
import okhttp3.*;
import java.io.File;
public class CompressDemo {
public static void main(String[] args) throws Exception {
OkHttpClient client = new OkHttpClient();
File file = new File("document.pdf");
RequestBody body = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", file.getName(),
RequestBody.create(file, MediaType.parse("application/pdf")))
.addFormDataPart("quality", "high")
.build();
Request request = new Request.Builder()
.url("https://api.uglypear.com/v1/compress")
.addHeader("Authorization", "Bearer YOUR_API_KEY")
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
}
}
}
API Response Format
After a successful compression request, the server returns a JSON-format response containing the task identifier and compression result information
{
"task_id": "task_8f3c2a1b9e7d4c5f",
"status": "completed",
"download_url": "https://api.uglypear.com/v1/tasks/task_8f3c2a1b9e7d4c5f/download",
"original_size": 5242880,
"compressed_size": 1572864,
"compression_ratio": "70.0%"
}
task_id
The unique identifier for this compression task, which can be used to query task status, download result files, or delete the task.
status
Task status, values are pending / processing / completed / failed.
download_url
The download URL for the compressed result file. Once the task is complete, you can retrieve the compressed file via this link.
original_size
Original file size in bytes.
compressed_size
Compressed file size in bytes.
compression_ratio
Compression ratio, representing the percentage of size reduction. A higher value means better compression.
Next Steps
After completing your first call, you can dive deeper into the complete API documentation, download SDKs for various languages, or view more code examples
API Docs
Review the complete OpenAPI 3.0 specification, parameter definitions, error codes, and rate limiting policies.
View API DocsSDK Download
Download the Rust SDK dynamic library, C FFI header files, and Python binding package to accelerate integration development.
Download SDKCode Examples
View complete example code for typical scenarios such as batch compression, async tasks, and encrypted compression.
View ExamplesView Complete API Documentation
Start building your compression integration solution with all interface descriptions, parameter definitions, and error code references