Tài liệu API

Tải lên file theo chương trình bằng API keys. Hỗ trợ các loại APK, IPA với trích xuất metadata tự động.

Tổng quan

AppDrop cung cấp API đơn giản và an toàn để tải lên file. Quy trình tải lên bao gồm ba bước:

1

Lấy Presigned URL

Yêu cầu URL tải lên an toàn từ API

2

Tải lên S3

Tải file trực tiếp lên AWS S3

3

Hoàn thành tải lên

Hoàn tất và xử lý tải lên

Bắt đầu - Tạo API Key

Trước khi sử dụng API, bạn cần tạo API key. Làm theo các bước sau để bắt đầu:

Bước 1: Tạo tài khoản người dùng

Đầu tiên, bạn cần tạo tài khoản người dùng trên AppDrop.

  • Đi đến trang Đăng ký Đi đến trang Đăng ký
  • Điền email và mật khẩu
  • Xác minh địa chỉ email
  • Hoàn tất thiết lập hồ sơ

Bước 2: Truy cập Dashboard

Sau khi tạo tài khoản, truy cập dashboard để quản lý API keys.

Bước 3: Tạo dự án (Bắt buộc)

Tạo dự án trước - API keys cần được liên kết với dự án.

  • Trong Dashboard, nhấp nút "Tạo dự án"
  • Nhập tên và mô tả dự án
  • Chọn màu cho dự án
  • Nhấp "Tạo dự án" để lưu
  • Lưu ý: Lưu ý: Bạn phải có ít nhất một dự án trước khi tạo API keys

Bước 4: Tạo API Key

Bây giờ tạo API key để bắt đầu sử dụng API.

  • Trong Dashboard, nhấp tab "Bảo mật"
  • Nhấp nút "Cài đặt nhà phát triển"
  • Nhấp nút "Tạo khóa mới"
  • Nhập tên cho API key
  • Chọn dự án (bắt buộc)
  • Nhấp "Tạo khóa" để tạo
  • Quan trọng: Quan trọng: Sao chép Client ID và Client Secret ngay lập tức

Bước 5: Sử dụng API Key

Bây giờ bạn đã sẵn sàng sử dụng API với thông tin đăng nhập.

  • Sử dụng Client ID trong header X-Client-ID X-Client-ID header
  • Sử dụng Client Secret trong header Authorization: Bearer Authorization: Bearer header
  • Làm theo tài liệu API bên dưới để tải lên file

⚠️ Lưu ý bảo mật quan trọng

  • Giữ Client Secret an toàn và không bao giờ để lộ trong code phía client
  • API keys được liên kết với tài khoản người dùng và dự án
  • Bạn có thể tạo lại API keys nếu cần
  • Theo dõi việc sử dụng API trong Cài đặt nhà phát triển

Xác thực

Tất cả yêu cầu API cần xác thực bằng API keys. Bạn có thể tạo API keys trong Cài đặt nhà phát triển.

Headers bắt buộc

X-Client-ID: your_client_id
Authorization: Bearer your_client_secret
Content-Type: application/json

Quy trình tải lên

Bước 1: Lấy Presigned URL

Yêu cầu presigned URL để tải lên trực tiếp lên S3. URL này có hiệu lực trong 15 phút.

Yêu cầu:
POST /api/upload/api-key/presign
{
  "fileName": "app.apk",
  "fileSize": 1048576,
  "fileType": "application/vnd.android.package-archive"
}

Bước 2: Tải lên S3

Tải file trực tiếp lên AWS S3 bằng presigned URL.

Yêu cầu:
PUT {presigned_url}
Content-Type: application/octet-stream
Body: file_binary_data

Bước 3: Hoàn thành tải lên

Thông báo cho API rằng việc tải lên đã hoàn tất và xử lý file.

Yêu cầu:
POST /api/upload/api-key/complete
{
  "key": "s3_key_from_step_1",
  "fileName": "app.apk",
  "fileType": "application/vnd.android.package-archive",
  "fileSize": 1048576
}

API Endpoints

POST/api/upload/api-key/presign

Lấy presigned URL để tải lên file

Phản hồi:
{
  "fileId": "507f1f77bcf86cd799439011",
  "key": "uploads/user123/app.apk",
  "uploadUrl": "https://s3.amazonaws.com/...",
  "expireAt": "2024-01-01T12:00:00Z"
}
POST/api/upload/api-key/complete

Hoàn thành quy trình tải lên

Phản hồi:
{
  "message": "Tải lên hoàn tất thành công",
  "fileId": "507f1f77bcf86cd799439011",
  "userKey": "abc123def456",
  "downloadUrl": "https://...",
  "shareUrl": "https://appdrop.com/share/abc123def456",
  "metadata": {
    "appName": "MyApp",
    "bundleId": "com.example.myapp",
    "version": "1.0.0"
  }
}

Mẫu code

Go Mẫu
package main

import (
    "bytes"
    "encoding/json"
    "net/http"
    "os"
)

func main() {
    clientID := "your_client_id"
    clientSecret := "your_client_secret"
    apiBaseURL := "https://api.app-dr.com"
    filePath := "test.ipa"

    file, err := os.Open(filePath)
    if err != nil {
        return
    }
    defer file.Close()

    fileInfo, _ := file.Stat()
    fileSize := fileInfo.Size()

    // Step 1: Get presigned URL
    presignData := map[string]interface{}{
        "fileName": fileInfo.Name(),
        "fileSize": fileSize,
        "fileType": "application/octet-stream",
    }
    jsonData, _ := json.Marshal(presignData)

    req, _ := http.NewRequest("POST", apiBaseURL+"/api/upload/api-key/presign", bytes.NewBuffer(jsonData))
    req.Header.Set("X-Client-ID", clientID)
    req.Header.Set("Authorization", "Bearer "+clientSecret)
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        return
    }
    defer resp.Body.Close()

    if resp.StatusCode != 200 {
        return
    }

    var presignResult map[string]interface{}
    json.NewDecoder(resp.Body).Decode(&presignResult)

    uploadURL, ok1 := presignResult["uploadUrl"].(string)
    s3Key, ok2 := presignResult["key"].(string)
    if !ok1 || !ok2 {
        return
    }

    // Step 2: Upload file to S3
    file.Seek(0, 0)
    uploadReq, _ := http.NewRequest("PUT", uploadURL, file)
    uploadReq.ContentLength = fileSize

    uploadResp, err := client.Do(uploadReq)
    if err != nil {
        return
    }
    defer uploadResp.Body.Close()

    if uploadResp.StatusCode != 200 {
        return
    }

    // Step 3: Complete upload
    completeData := map[string]interface{}{
        "key":      s3Key,
        "fileName": fileInfo.Name(),
        "fileType": "application/octet-stream",
        "fileSize": fileSize,
    }
    completeJson, _ := json.Marshal(completeData)

    completeReq, _ := http.NewRequest("POST", apiBaseURL+"/api/upload/api-key/complete", bytes.NewBuffer(completeJson))
    completeReq.Header.Set("X-Client-ID", clientID)
    completeReq.Header.Set("Authorization", "Bearer "+clientSecret)
    completeReq.Header.Set("Content-Type", "application/json")

    completeResp, err := client.Do(completeReq)
    if err != nil {
        return
    }
    defer completeResp.Body.Close()

    if completeResp.StatusCode != 200 {
        return
    }

    var completeResult map[string]interface{}
    json.NewDecoder(completeResp.Body).Decode(&completeResult)
}

Giới hạn tốc độ

Yêu cầu API bị giới hạn tốc độ để đảm bảo sử dụng công bằng và ổn định hệ thống.

Giới hạn tốc độ

  • 100 yêu cầu mỗi phút cho mỗi API key
  • Headers giới hạn tốc độ có trong phản hồi
  • Mã trạng thái 429 khi vượt quá giới hạn

Headers giới hạn tốc độ

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640995200