MCPcopy Create free account
hub / github.com/diwosuwanto/cloudflare-r2-with-nextjs-upload-download-delete

github.com/diwosuwanto/cloudflare-r2-with-nextjs-upload-download-delete @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
20 symbols 39 edges 10 files ⚖ MIT 0 documented · 0% updated 1y ago★ 39

Browse by type

Functions 19 Types & classes 1
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Cloudflare R2 with Next.js: Upload, Download, Delete

This is a Next.js project that demonstrates how to integrate Cloudflare R2 for file upload, download, and deletion functionalities. It is bootstrapped with create-next-app.

https://github.com/user-attachments/assets/9b5b8922-167c-4519-a49c-5efbc932c999

Table of Contents

Installation

To install the necessary dependencies, run the following command:

npm install
# or
yarn install
# or
pnpm install
# or
bun install

Getting Started

To run the project, first ensure you have installed the necessary dependencies. Then, start the development server:

npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev

Open http://localhost:3000 with your browser to see the result.

Features

  • Upload files to Cloudflare R2: Users can upload files directly to Cloudflare R2 storage.
  • Download files from Cloudflare R2: Users can download files stored in Cloudflare R2.
  • Delete files from Cloudflare R2: Users can delete files from Cloudflare R2.
  • Progress indication during file uploads: Users receive feedback on the upload progress.
  • Responsive UI: The application is designed to be responsive and user-friendly.

Project Structure

The project is structured as follows:

/src
  /app
    /api
      /files
        route.ts         # API routes for file operations
      /upload
        route.ts         # API route for file upload
    /components
      file-manager.tsx   # Component for managing file uploads, downloads, and deletions
    layout.tsx           # Main layout component
    page.tsx             # Home page component
  /utils
    r2.ts                # Utility functions for interacting with Cloudflare R2
/globals.css             # Global styles

API Endpoints

File Operations

  • GET /api/files: Lists all files in the Cloudflare R2 bucket.
  • POST /api/files: Generates a signed URL for downloading a specific file.
  • DELETE /api/files: Deletes a specified file from the Cloudflare R2 bucket.

Upload File

  • POST /api/upload: Generates a signed URL for uploading a file to Cloudflare R2.

Environment Variables

Make sure to set the following environment variables in your .env file:

R2_ACCOUNT_ID=<your_r2_account_id>
R2_ACCESS_KEY_ID=<your_r2_access_key_id>
R2_SECRET_ACCESS_KEY=<your_r2_secret_access_key>
R2_BUCKET=<your_r2_bucket_name>

Package Details

This project uses the following packages:

Dependencies

  • @aws-sdk/client-s3: ^3.627.0 - AWS SDK for JavaScript S3 client.
  • @aws-sdk/s3-request-presigner: ^3.627.0 - Presigner for S3 requests.
  • next: 14.2.5 - The React framework for production.
  • react: ^18 - A JavaScript library for building user interfaces.
  • react-dom: ^18 - React package for working with the DOM.

Dev Dependencies

  • @types/node: ^20 - TypeScript definitions for Node.js.
  • @types/react: ^18 - TypeScript definitions for React.
  • @types/react-dom: ^18 - TypeScript definitions for React DOM.
  • eslint: ^8 - A tool for identifying and reporting on patterns in JavaScript.
  • eslint-config-next: 14.2.5 - ESLint configuration for Next.js.
  • postcss: ^8 - A tool for transforming CSS with JavaScript plugins.
  • tailwindcss: ^3.4.1 - A utility-first CSS framework.
  • typescript: ^5 - A superset of JavaScript that compiles to clean JavaScript output.

License

This project is licensed under the MIT License.

Extension points exported contracts — how you extend this code

browse all types & interfaces →

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 19
Interface 1

Languages

TypeScript100%

Modules by API surface

src/components/file-manager.tsx8 symbols
src/utils/r2.ts6 symbols
src/app/api/files/route.ts3 symbols
src/app/page.tsx1 symbols
src/app/layout.tsx1 symbols
src/app/api/upload/route.ts1 symbols

For agents

$ claude mcp add cloudflare-r2-with-nextjs-upload-download-delete \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page