1.0.16 • Published 10 months ago
clouflare-r2-file-upload v1.0.16
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
Option | Required | Default | Description |
---|---|---|---|
handleInputChange | Yes | ||
title | No | ||
subtitle | No | ||
choseTitle | Yes | ||
style | No | ||
acceptFileTypesText | Yes | ||
message | No | ||
type | No | ||
acceptedFileTypes | Yes | ||
changeImageName | No | false | If 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:
- Installation: Instructions on how to install the component.
- Usage: Examples showing how to use the component for single and multiple file uploads.
- Props: Detailed explanation of the props accepted by the
FileUpload
component. - Environment Variables: Description of the required environment variables for configuring the component.
- Features: List of features supported by the component.
- License: License information for the component.
This README should provide a comprehensive guide for users to understand and use your file upload component.