FileUpload is an advanced file upload component with drag-and-drop functionality, automatic validation, and integration with upload APIs. It offers an intuitive interface for selecting and uploading files with full visual feedback.tsx
import { FileUpload } from "@arkyn/components";
name and action properties.Ou arraste e solte o arquivo aqui
tsx
<FileUpload name="document" action="/api/upload" label="Select a file" />
action must accept upload requests via POST and return a JSON file with the URL of the uploaded file or an error message.tsx
// Success response example{ "url": "https://yourdomain.com/uploads/filename.ext" }// Error response example{ "error": "File type not supported" }
Drag your image here
tsx
<FileUploadname="avatar"action="/api/upload/avatar"label="Profile Picture"showAsteriskacceptFile="image/*"selectFileButtonText="Choose Image"changeFileButtonText="Change Image"dropFileText="Drag your image here"onChange={(url) => console.log("Avatar uploaded:", url)}/>
acceptFile property.Drag PDF file here
Drag video here
Ou arraste e solte o arquivo aqui
tsx
// Upload PDF<FileUploadname="contract"action="/api/upload/document"label="Contract (PDF)"acceptFile=".pdf"selectFileButtonText="Select PDF"dropFileText="Drag PDF file here"/>// Video Upload<FileUploadname="presentation"action="/api/upload/video"label="Presentation Video"acceptFile="video/mp4,video/webm"selectFileButtonText="Choose Video"dropFileText="Drag video here (MP4 or WebM)"/>// Multiple Types<FileUploadname="media"action="/api/upload/media"label="Image or Video"acceptFile="image/*,video/*"selectFileButtonText="Select Media"/>
Ou arraste e solte o arquivo aqui
tsx
<FileUploadname="document"action="/api/upload"label="Upload Temporarily Unavailable"disabled/>
errorMessage property, it will take precedence over messages from the form provider.Ou arraste e solte o arquivo aqui
tsx
<FileUploadname="avatar"action="/api/upload/avatar"label="Profile Picture"showAsteriskacceptFile="image/*"errorMessage="Please upload a valid image"onChange={(url) => console.log("Avatar uploaded:", url)}/>
name - string (required)
Field name for form manipulationaction - string (required)
URL of the endpoint where the file is located.
The file will be uploaded.disabled - boolean (default: false)
If file upload is disabled.label - string
Label text to display above the upload area.showAsterisk - boolean (default: false)
Whether to display an asterisk in the label for required fields.changeFileButtonText - string (default: "Change file")
Button text to change/replace an already uploaded file.selectFileButtonText - string (default: "Select file")
Button text to select a file.dropFileText - string (default: "Or drag and drop the file here")
Text displayed in the drop zone.method - string (default: "POST")
HTTP method for the upload requestfileName - string (default: "file")
Name of the field in the FormData for the filefileResponseName - string (default: "url")
Name of the property in the response object that contains the file URLacceptFile - string (default: "*")
File types accepted by the input (e.g., "image/*", ".pdf")onChange - (url?: string) => void
Callback function called when the upload is successfulactionacceptFile to restrict formatsonChange callback for feedback