Skip to content

Commit

Permalink
sdp-tech#78 feat: limit uploadable file conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
eujin-shin committed Jul 20, 2024
1 parent d0a84f5 commit 525fb83
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/common/FilePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ReactNode } from 'react';
import { Alert, TouchableOpacity, ViewStyle } from 'react-native';
import {
DocumentPickerOptions,
DocumentPickerResponse,
pick,
types,
isCancel,
} from 'react-native-document-picker';

interface FilePickerProps {
Expand All @@ -19,13 +19,18 @@ const FilePicker = ({
callback,
disabled,
}: FilePickerProps) => {
const MEGABYTE = 1000000;

const handleFile = async () => {
try {
const [selectedFile] = await pick();
callback(selectedFile);
const [selectedFile] = await pick({ type: [types.pdf] });
if (selectedFile.size !== null && selectedFile.size > 20 * MEGABYTE) {
Alert.alert('크기 제한을 초과하는 파일입니다.');
} else {
callback(selectedFile);
}
} catch (e: unknown) {
console.log(e);
Alert.alert('파일 업로드에 실패했습니다.');
if (!isCancel(e)) Alert.alert('파일 업로드에 실패했습니다.');
}
};

Expand Down

0 comments on commit 525fb83

Please sign in to comment.