Storage

From tinh2/skills-hub-registry · View interactive version

Storage is an AI agent skill from the GitHub repository tinh2/skills-hub-registry. Add file uploads and object storage to my app — set up AWS S3, Google Cloud Storage, Cloudflare R2, or Supabase Storage with presigned URLs, direct browser uploads, multipart chunked uploads, file type validation, lifecycle policies, CORS configuration, and CDN integration

How to use this skill

Skill file

You are in AUTONOMOUS MODE. Do NOT ask questions. Detect everything from the codebase and proceed.

PURPOSE:

Set up production-ready object storage. Auto-detect the project's framework and the requested

storage provider. Install the SDK, create a storage service with full CRUD operations, configure

presigned URLs for secure direct uploads, set up lifecycle policies, CORS, CDN integration, and

handle multipart uploads for large files.

TASK:

$ARGUMENTS

============================================================ PHASE 0: DETECTION ============================================================

  1. FRAMEWORK DETECTION — scan the project root to identify the tech stack:
  1. PROVIDER DETECTION — determine storage provider from $ARGUMENTS or existing config:
  1. EXISTING STORAGE CHECK — search for existing storage wrappers:
  1. BACKEND REQUIREMENT CHECK:

============================================================ PHASE 1: SDK INSTALLATION ============================================================

Install the correct SDK for the detected provider and framework:

AWS S3:

GOOGLE CLOUD STORAGE:

CLOUDFLARE R2:

SUPABASE STORAGE:

After installing:

============================================================ PHASE 2: STORAGE SERVICE ============================================================

Create a storage service that abstracts the provider. This lets the team swap providers

(e.g., S3 to R2) without touching application code.

FILE LOCATION:

THE SERVICE MUST EXPOSE:

init(config)

Initialize the storage client with credentials and bucket name.

upload(key, file, options?)

Upload a file to storage. Options: contentType, metadata, acl, onProgress callback.

Returns: { key, url, size, contentType }.

download(key)

Download a file by key. Returns a stream or buffer depending on framework.

delete(key)

Delete a single object by key. Idempotent — no error if key does not exist.

deleteMany(keys)

Batch delete multiple objects. Use the provider's bulk delete API.

list(prefix?, options?)

List objects with optional prefix filter. Options: maxKeys, cursor/continuationToken.

Returns: { objects: [{ key, size, lastModified }], cursor?, hasMore }.

getUrl(key)

Get the public URL for an object (if bucket is public or CDN is configured).

getSignedUrl(key, options?)

Generate a presigned URL for private access. Options: expiresIn (seconds, default 3600),

method ("GET" or "PUT"), contentType (for PUT).

getUploadUrl(key, contentType, options?)

Generate a presigned PUT URL for direct browser uploads.

Returns: { uploadUrl, fields?, key }.

copy(sourceKey, destinationKey)

Server-side copy without downloading.

getMetadata(key)

Get object metadata (size, contentType, lastModified, custom metadata).

IMPLEMENTATION REQUIREMENTS:

============================================================ PHASE 3: FILE VALIDATION ============================================================

Create a validation layer that runs before every upload:

FILE: src/lib/storage-validation.ts (or framework equivalent)

  1. FILE TYPE VALIDATION:
  1. FILE SIZE VALIDATION:
  1. FILENAME SANITIZATION:
  1. IMAGE PROCESSING (if applicable):

============================================================ PHASE 4: PRESIGNED URLS & DIRECT UPLOAD ============================================================

Implement secure direct-to-storage uploads from the browser/client:

  1. SERVER-SIDE ENDPOINT — create an API route:
  1. CLIENT-SIDE UPLOAD HELPER:
  1. MULTIPART UPLOAD (files > 10MB):

============================================================ PHASE 5: CORS CONFIGURATION ============================================================

Generate CORS configuration for the storage bucket:

AWS S3 / R2:

{
  "CORSRules": [{
    "AllowedHeaders": ["*"],
    "AllowedMethods": ["GET", "PUT", "POST", "DELETE", "HEAD"],
    "AllowedOrigins": ["${APP_URL}"],
    "ExposeHeaders": ["ETag", "Content-Length", "x-amz-request-id"],
    "MaxAgeSeconds": 3600
  }]
}

GCS:

[{
  "origin": ["${APP_URL}"],
  "method": ["GET", "PUT", "POST", "DELETE", "HEAD"],
  "responseHeader": ["Content-Type", "Content-Length"],
  "maxAgeSeconds": 3600
}]

============================================================ PHASE 6: LIFECYCLE POLICIES ============================================================

Create lifecycle rules to manage storage costs:

  1. TEMP FILES — auto-delete after 24 hours:
  1. OLD VERSIONS — archive or delete after 90 days:
  1. INCOMPLETE MULTIPART — auto-abort after 7 days:
  1. LOG ARCHIVAL (if applicable):

Write lifecycle config to storage/lifecycle.json with provider-specific format.

Include CLI commands to apply the policies as comments in the file.

============================================================ PHASE 7: CDN INTEGRATION ============================================================

Set up CDN for serving stored files:

  1. CDN URL HELPER:
  1. CACHE HEADERS:
  1. CONFIGURATION FILE:

============================================================ PHASE 8: VALIDATION ============================================================

  1. Run the project's build/compile step — fix any errors.
  2. Run existing tests — fix any failures caused by storage integration.
  3. Verify the storage service can be imported and instantiated without errors.
  4. Write at least 3 unit tests for the storage service:
  1. Commit all changes with descriptive messages:

============================================================ DO NOT ============================================================

============================================================ OUTPUT ============================================================

Storage Setup

NEXT STEPS:

After storage is set up:

============================================================

SELF-HEALING VALIDATION (max 3 iterations)

============================================================

After completing the integration, validate:

  1. Run the project's test suite to verify the integration works end-to-end.
  2. Run build/compile to confirm no breakage.
  3. Verify the integration responds correctly (health checks, test calls, smoke tests).
  4. If failures occur, diagnose from error output and apply minimal fixes.
  5. Repeat up to 3 iterations.

IF STILL FAILING after 3 iterations:

============================================================

SELF-EVOLUTION TELEMETRY

============================================================

After producing output, record execution metadata for the /evolve pipeline.

Check if a project memory directory exists:

Entry format:

### /storage — {{YYYY-MM-DD}}
- Outcome: {{SUCCESS | PARTIAL | FAILED}}
- Self-healed: {{yes — what was healed | no}}
- Iterations used: {{N}} / {{N max}}
- Bottleneck: {{phase that struggled or "none"}}
- Suggestion: {{one-line improvement idea for /evolve, or "none"}}

Only log if the memory directory exists. Skip silently if not found.

Keep entries concise — /evolve will parse these for skill improvement signals.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.