मुख्य सामग्री पर जाएं

विकल्प संदर्भ

useDropup हुक के लिए सभी कॉन्फ़िगरेशन विकल्प।

सत्यापन विकल्प

accept

स्वीकार करने के लिए फाइल प्रकार।

// एकल MIME प्रकार
useDropup({ accept: 'image/png' });

// एकाधिक MIME प्रकार
useDropup({ accept: 'image/png, image/jpeg, image/gif' });

// वाइल्डकार्ड
useDropup({ accept: 'image/*' });

// एक्सटेंशन द्वारा
useDropup({ accept: '.pdf, .doc, .docx' });

// ऐरे फॉर्मैट
useDropup({ accept: ['image/*', 'application/pdf', '.txt'] });
प्रकारडिफ़ॉल्ट
string | string[]undefined (सभी फाइलें)

maxSize

बाइट्स में अधिकतम फाइल आकार।

useDropup({ maxSize: 10 * 1024 * 1024 }); // 10MB
प्रकारडिफ़ॉल्ट
numberundefined (कोई सीमा नहीं)

minSize

बाइट्स में न्यूनतम फाइल आकार।

useDropup({ minSize: 1024 }); // न्यूनतम 1KB
प्रकारडिफ़ॉल्ट
numberundefined (कोई सीमा नहीं)

maxFiles

अनुमत फाइलों की अधिकतम संख्या।

useDropup({ maxFiles: 5 });
प्रकारडिफ़ॉल्ट
numberundefined (कोई सीमा नहीं)

maxWidth / maxHeight

पिक्सेल में अधिकतम छवि आयाम।

useDropup({
accept: 'image/*',
maxWidth: 4096,
maxHeight: 4096,
});
प्रकारडिफ़ॉल्ट
numberundefined (कोई सीमा नहीं)

minWidth / minHeight

पिक्सेल में न्यूनतम छवि आयाम।

useDropup({
accept: 'image/*',
minWidth: 100,
minHeight: 100,
});
प्रकारडिफ़ॉल्ट
numberundefined (कोई सीमा नहीं)

customRules

कस्टम सत्यापन फंक्शन।

useDropup({
customRules: [
// सिंक सत्यापन
(file) => {
if (file.name.includes('draft')) {
return 'ड्राफ्ट फाइलों की अनुमति नहीं है';
}
return true;
},
// एसिंक सत्यापन
async (file) => {
const exists = await checkServerDuplicate(file);
return exists ? 'फाइल पहले से मौजूद है' : true;
},
],
});
प्रकारडिफ़ॉल्ट
ValidationRule[][]

ValidationRule प्रकार:

type ValidationRule = (file: File) => boolean | string | Promise<boolean | string>;

व्यवहार विकल्प

multiple

एकाधिक फाइल चयन की अनुमति दें।

useDropup({ multiple: true });  // एकाधिक फाइलें
useDropup({ multiple: false }); // केवल एक फाइल
प्रकारडिफ़ॉल्ट
booleantrue

disabled

ड्रॉपजोन को अक्षम करें।

useDropup({ disabled: true });
प्रकारडिफ़ॉल्ट
booleanfalse

autoUpload

फाइलें जोड़ने पर स्वचालित रूप से अपलोड शुरू करें।

useDropup({
upload: { url: '/api/upload' },
autoUpload: true,
});
प्रकारडिफ़ॉल्ट
booleanfalse

generatePreviews

छवि फाइलों के लिए प्रीव्यू URLs जनरेट करें।

useDropup({ generatePreviews: true });

// प्रीव्यू एक्सेस करें
files[0].preview // "blob:http://..."
प्रकारडिफ़ॉल्ट
booleantrue

अपलोड कॉन्फ़िगरेशन

upload

अपलोड गंतव्य और व्यवहार कॉन्फ़िगर करें।

URL-आधारित कॉन्फ़िगरेशन

useDropup({
upload: {
url: '/api/upload',
method: 'POST',
headers: {
'Authorization': 'Bearer token',
},
fieldName: 'file',
withCredentials: true,
timeout: 30000,
},
});

UploadConfig गुण:

गुणप्रकारडिफ़ॉल्टविवरण
urlstringआवश्यकअपलोड एंडपॉइंट URL
methodstring'POST'HTTP मेथड
headersRecord<string, string>{}रिक्वेस्ट हेडर्स
fieldNamestring'file'फाइल के लिए फॉर्म फील्ड नाम
withCredentialsbooleanfalseकुकीज़ शामिल करें
timeoutnumber0रिक्वेस्ट टाइमआउट (ms)
dataRecord<string, unknown>{}अतिरिक्त फॉर्म डेटा

कस्टम अपलोडर

useDropup({
upload: async (file, options) => {
const formData = new FormData();
formData.append('file', file.file);

const response = await fetch('/api/upload', {
method: 'POST',
body: formData,
signal: options.signal,
});

const data = await response.json();
return { url: data.url };
},
});

CustomUploader प्रकार:

type CustomUploader = (
file: DropupFile,
options: UploadOptions
) => Promise<UploadResult>;

interface UploadOptions {
signal: AbortSignal;
onProgress: (progress: number) => void;
}

interface UploadResult {
url?: string;
response?: unknown;
}

क्लाउड अपलोडर्स

import { createS3Uploader } from '@samithahansaka/dropup/cloud/s3';

useDropup({
upload: createS3Uploader({
getPresignedUrl: async (file) => {
const res = await fetch('/api/s3-presign', {
method: 'POST',
body: JSON.stringify({ filename: file.name, type: file.type }),
});
return res.json();
},
}),
});

कॉलबैक विकल्प

onFilesAdded

फाइलें जोड़ने पर कॉल होता है (सत्यापन के बाद)।

useDropup({
onFilesAdded: (files) => {
console.log('जोड़ा गया:', files.map(f => f.name));
},
});
प्रकार
(files: DropupFile[]) => void

onFileRemoved

फाइल हटाने पर कॉल होता है।

useDropup({
onFileRemoved: (file) => {
console.log('हटाया गया:', file.name);
},
});
प्रकार
(file: DropupFile) => void

onValidationError

फाइलें सत्यापन में विफल होने पर कॉल होता है।

useDropup({
accept: 'image/*',
onValidationError: (errors) => {
errors.forEach(({ file, errors }) => {
console.log(`${file.name}: ${errors.join(', ')}`);
});
},
});
प्रकार
(errors: ValidationError[]) => void

onUploadStart

फाइल अपलोड शुरू होने पर कॉल होता है।

useDropup({
onUploadStart: (file) => {
console.log('अपलोड शुरू:', file.name);
},
});
प्रकार
(file: DropupFile) => void

onUploadProgress

अपलोड प्रगति के दौरान कॉल होता है।

useDropup({
onUploadProgress: (file, progress) => {
console.log(`${file.name}: ${progress}%`);
},
});
प्रकार
(file: DropupFile, progress: number) => void

onUploadComplete

फाइल अपलोड पूर्ण होने पर कॉल होता है।

useDropup({
onUploadComplete: (file, response) => {
console.log('अपलोड हुआ:', file.uploadedUrl);
console.log('सर्वर प्रतिक्रिया:', response);
},
});
प्रकार
(file: DropupFile, response: unknown) => void

onUploadError

फाइल अपलोड विफल होने पर कॉल होता है।

useDropup({
onUploadError: (file, error) => {
console.error(`विफल: ${file.name}`, error.message);
},
});
प्रकार
(file: DropupFile, error: DropupError) => void

onAllComplete

सभी फाइलें अपलोड समाप्त होने पर कॉल होता है।

useDropup({
onAllComplete: (files) => {
const successful = files.filter(f => f.status === 'complete');
console.log(`${successful.length}/${files.length} सफलतापूर्वक अपलोड हुए`);
},
});
प्रकार
(files: DropupFile[]) => void

पूर्ण उदाहरण

const { files, actions, state, getDropProps, getInputProps } = useDropup({
// सत्यापन
accept: ['image/*', 'application/pdf'],
maxSize: 10 * 1024 * 1024,
maxFiles: 5,

// व्यवहार
multiple: true,
autoUpload: false,
generatePreviews: true,

// अपलोड
upload: {
url: '/api/upload',
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
},
},

// कॉलबैक
onFilesAdded: (files) => {
toast.info(`${files.length} फाइल(ें) जोड़ी गईं`);
},
onValidationError: (errors) => {
toast.error(`${errors.length} फाइल(ें) अस्वीकृत`);
},
onUploadProgress: (file, progress) => {
console.log(`${file.name}: ${progress}%`);
},
onUploadComplete: (file) => {
toast.success(`${file.name} अपलोड हुई!`);
},
onUploadError: (file, error) => {
toast.error(`${file.name} विफल: ${error.message}`);
},
onAllComplete: (files) => {
const count = files.filter(f => f.status === 'complete').length;
toast.success(`सभी पूर्ण! ${count} फाइलें अपलोड हुईं।`);
},
});