1.0.16 • Published 10 months ago

clouflare-r2-file-upload v1.0.16

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

Cloudflare R2 File Upload

A React component for uploading files to Cloudflare R2, with support for single and multiple file uploads. Includes drag-and-drop functionality and integration with react-dropzone.

Meta

  • Create and publish the component
  • Add diferent styles
  • Add customizable styles

Installation

Install the package via npm:

npm install @cloudflare/r2-file-upload

Add environment variables for your Cloudflare R2 API key and account ID:

VITE_AWS_ACCESS_KEY_ID=your_access_key_id
VITE_AWS_SECRET_ACCESS_KEY=your_secret_access_key
VITE_AWS_REGION=your_region # e.g. auto
VITE_AWS_ENDPOINT=your_endpoint # e.g. https://7361411401e98074.eu.r2.cloudflarestorage.com
VITE_AWS_BUCKET_NAME=your_bucket_name # e.g. test-bucket
VITE_IMG_DOMAIN=your_img_domain # e.g. https://lolo.com.com (this domain added in your R2 bucket settings for public access)

Props

OptionRequiredDefaultDescription
handleInputChangeYes
titleNo
subtitleNo
choseTitleYes
styleNo
acceptFileTypesTextYes
messageNo
typeNo
acceptedFileTypesYes
changeImageNameNofalseIf true, the file name will be changed to a random UUID. This is useful when you want to upload multiple files with the same name.

Usage

Import the FileUpload component and use it in your React application:

import { FileUpload } from "@cloudflare/r2-file-upload";

function App() {

const [formData, setFormData] = useState<{ imageUrl: string[] }>({
    imageUrl: [],
  });

const handleInputChange = (urls: string[]) => {
    setFormData({ ...formData, imageUrl: urls });
  };

  return (
    <FileUpload
      handleInputChange={handleInputChange}
      title="Upload to Cloudflare R2 multiple"
      subtitle="Upload here"
      choseTitle="Attach File"
      style="simple"
      acceptFileTypesText="image, pdf, doc, txt, docx no more than 10MB"
      message="Drag and drop the file you want to upload"
      type="multiple"
      acceptedFileTypes={[
        "image/*",
        "application/pdf",
        ".doc",
        ".txt",
        ".docx",
      ]}
    />
  );
}

Explanation:

  1. Installation: Instructions on how to install the component.
  2. Usage: Examples showing how to use the component for single and multiple file uploads.
  3. Props: Detailed explanation of the props accepted by the FileUpload component.
  4. Environment Variables: Description of the required environment variables for configuring the component.
  5. Features: List of features supported by the component.
  6. License: License information for the component.

This README should provide a comprehensive guide for users to understand and use your file upload component.

1.0.16

10 months ago

1.0.11

10 months ago

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.10

12 months ago

1.0.9

12 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago