Skip to content
/ cycloop Public

A lightweight TypeScript-based upload service that integrates the AWS S3 SDK to handle file uploads, optimized for Cloudflare R2 storage

Notifications You must be signed in to change notification settings

pace11/cycloop

Repository files navigation

⛰️ CYCLOOP

Service Upload with S3 SDK and Cloudflare R2


🔀 Basic Request

  • CURL example
curl --location 'http://localhost:4100/api/upload' \
--header 'x-api-key: [secret key]' \
--form 'file=@"/path/to/file"'
  • Javascript Fetch example
const formData = new FormData()
formData.append('file', fileInput.files[0])

fetch('http://localhost:4100/api/upload', {
  method: 'POST',
  headers: {
    'x-api-key': 'your-secret-key-here',
  },
  body: formData,
})
  .then((res) => res.json())
  .then((data) => console.log('Success:', data))
  .catch((err) => console.error('Upload error:', err))
  • Response 201
{
  "data": {
    "url": "https://cloudflare.com/file_name.jpeg",
    "name": "file_name.jpeg",
    "size": 12345
  },
  "message": "Upload successful"
}
  • Response 400
{
  "data": null,
  "message": "No file uploaded!"
}
  • Response 401
{
  "error": "Unauthorized"
}
  • Response 500
{
  "error": "Upload error"
}

🏃 How to run

  • Clone this repository
  • Copy .env.example to .env and adjust according to the Cloudflare R2 credentials you have

🕸️ Stack

  • Express.js + Typescript
  • Sharp (Compress image)
  • Aws SDK

📖 Docs

About

A lightweight TypeScript-based upload service that integrates the AWS S3 SDK to handle file uploads, optimized for Cloudflare R2 storage

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published