본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

업로드

원문 보기 위키 갱신

업로드 (Upload)

파일을 선택하거나 드래그해서 올리는 컴포넌트예요. 단일 업로드부터 여러 파일, 디렉터리 업로드, 업로드 목록 커스텀까지 폭넓게 지원해요.

출처: 문서

본문

API

Upload

속성 설명 타입 기본값 버전
autoUpload 파일을 고른 뒤 자동으로 업로드할지 여부 boolean true -
directory 디렉터리 전체 업로드를 지원해요 boolean - 2.11.0
disabled 비활성 여부 boolean - -
drag 드래그 앤 드롭 업로드를 켤지 여부 boolean - -
imagePreview 내장 이미지 미리보기를 켜요. listType='picture-card'일 때만 동작해요. (v2.41.0) boolean - -
multiple 여러 파일을 고를 수 있게 할지 여부 boolean - -
withCredentials 업로드 요청 시 쿠키를 실을지 여부 boolean - -
action 업로드 URL string - -
method 업로드 요청의 http 메서드 string post 2.55.0
listType 업로드 목록 스타일 'text' | 'picture-list' | 'picture-card' text -
tip 안내 텍스트 string | React.ReactNode - -
accept 허용하는 파일 타입(strict in 2.53.0, defaultValue is true. When set to false, accept behaves the same as native. When set to true, file extensions will be strictly matched and files that do not meet the accept rules will be filtered out. ) string | { type: string; strict?: boolean } - -
beforeUpload 업로드 직전의 콜백이에요. 반환 값이 false이거나 resolve(false) 또는 reject되는 Promise면 업로드가 중단돼요. (file: File, filesList: File[]) => boolean | Promise<any> () => true -
className 추가 css 클래스 string | string[] - -
defaultFileList 업로드된 파일의 기본 목록 UploadItem[] - -
fileList 업로드된 파일의 목록 UploadItem[] - -
headers 요청 헤더를 설정해요 object - -
limit 허용되는 최대 업로드 개수. 2.28.0부터 객체 타입을 지원해요 number | { maxCount: number; hideOnExceedLimit?: boolean } - -
onRemove 삭제 아이콘을 클릭했을 때의 콜백이에요. 반환 값이 false이거나 resolve(false) 또는 reject되는 Promise면 삭제 동작이 중단돼요. (file: UploadItem, fileList: UploadItem[]) => void | boolean | Promise<void | boolean> - -
progressProps Progress 컴포넌트의 props. Partial<ProgressProps> - -
showUploadList 업로드 목록을 보여 줄지 여부. 객체로 넘겨서 previewIcon, removeIcon,fileIcon, reuploadIcon, cancelIcon, startIcon, errorIcon, fileName을 커스텀할 수 있어요 boolean | CustomIconType true -
style 추가 스타일 CSSProperties - -
customRequest 기본 xhr 동작을 대체해서 추가 커스터마이즈를 할 수 있게 해 줘요 (options: RequestOptions) => UploadRequestReturn | void - -
data 요청에 실어 보낼 추가 파라미터 object | ((any: any) => object) - -
name 업로드 파일의 key 이름 string | ((any: any) => string) - -
onChange 업로드 상태가 바뀔 때의 콜백 (fileList: UploadItem[], file: UploadItem) => void - -
onDragLeave 드래그 업로드 파일이 드래그 영역을 벗어났을 때의 콜백 (e: React.DragEvent) => void - 2.41.0
onDragOver 드래그 업로드 파일이 드래그 영역으로 들어왔을 때의 콜백 (e: React.DragEvent) => void - 2.41.0
onDrop 파일을 업로드 영역으로 드래그해 놓은 뒤의 콜백. (e: React.DragEvent) => void - 2.37.0
onExceedLimit limit를 넘었을 때의 콜백 (files: File[], fileList: UploadItem[]) => void - -
onPreview 미리보기 아이콘을 클릭했을 때의 콜백 (file: UploadItem) => void - -
onProgress 업로드 진행률이 바뀌고 있을 때의 콜백 (file: UploadItem, e?: ProgressEvent) => void - -
onReupload 재업로드 아이콘을 클릭했을 때의 콜백 (file: UploadItem) => void - -
renderUploadItem uploadList의 항목을 커스텀해요 (originNode: ReactNode, file: UploadItem, fileList: UploadItem[]) => ReactNode - -
renderUploadList uploadList를 커스텀해요 (fileList: UploadItem[], uploadListProps: UploadListProps) => ReactNode - -

UploadListProps

파일 업로드 목록 표시

속성 설명 타입 기본값
disabled 비활성 여부 boolean -
onRemove 삭제 아이콘을 클릭했을 때의 콜백. 반환 값이 false이거나 resolve(false) 또는 reject되는 Promise면 삭제 동작이 중단돼요 (file: UploadItem) => void | boolean | Promise<void | boolean> -
onAbort 취소 아이콘을 클릭했을 때의 콜백 (file: UploadItem) => void -
onPreview 미리보기 아이콘을 클릭했을 때의 콜백 (file: UploadItem) => void -
onReupload 재업로드 아이콘을 클릭했을 때의 콜백 (file: UploadItem) => void -

UploadItem

속성 설명 타입 기본값
percent 업로드 진행률 퍼센트 number -
name 파일 이름 string -
uid 고유 식별자 string (Required) -
url 파일 url string -
originFile File 객체 File -
response 업로드 요청의 응답 object -
status 업로딩 상태 UploadStatus -

RequestOptions

export type RequestOptions = Pick<
  UploadProps,
  "headers" | "name" | "data" | "withCredentials" | "action" | "method"
> & {
  /** 更新当前文件的上传进度 。percent: 当前上传进度百分比 */
  onProgress: (percent: number, event?: ProgressEvent) => void;
  /** 上传成功后,调用onSuccess方法,传入的response参数将会附加到当前上传文件的reponse字段上 */
  onSuccess: (response?: object) => void;
  /** 上传失败后,调用onError方法,传入的 response 参数将会附加到当前上传文件的response字段 */
  onError: (response?: object) => void;
  /** 当前上传文件 */
  file: File;
};

UploadRequestReturn

export interface UploadRequestReturn {
  abort?: () => void;
  [key: string]: any;
}

CustomIconType

export type CustomIconType = {
  previewIcon?: ReactNode;
  removeIcon?: ReactNode;
  fileIcon?: ReactNode;
  reuploadIcon?: ReactNode;
  cancelIcon?: ReactNode;
  startIcon?: ReactNode;
  errorIcon?: ReactNode;
  successIcon?: ReactNode;
  fileName?: (file: UploadItem) => ReactNode;
  // 2.34.0
  progressRender?: (
    file: UploadItem,
    originDom: ReactNode
  ) => React.ReactElement;
  // 2.34.0
  imageRender?: (file: UploadItem) => React.ReactNode;
};

UploadStatus

export type UploadStatus = "init" | "uploading" | "done" | "error";

Methods

속성 설명 타입
submit 파일 목록을 직접 업로드해요. example. 파라미터가 없으면 init 상태의 모든 파일이 기본으로 업로드돼요. (file?: UploadItem) => void
abort 업로드 요청을 취소해요 (file: UploadItem) => void
reupload 재업로드 요청 (file: UploadItem) => void
// Custom icons
type CustomIconType = {
  previewIcon?: ReactNode;
  removeIcon?: ReactNode;
  fileIcon?: ReactNode;
  reuploadIcon?: ReactNode;
  cancelIcon?: ReactNode;
  startIcon?: ReactNode;
  errorIcon?: ReactNode;
  fileName?: (file: UploadItem) => ReactNode;
  progressRender?: (file: UploadItem, originDom: ReactNode) => ReactElement; // 2.34.0
  imageRender?: (file: UploadItem) => ReactNode; // 2.34.0
}

Q&A

업로드된 파일의 상태와 진행률은 어떻게 제어하나요?

example을 참고하세요. fileList의 각 요소에 status, percent 같은 필드를 직접 설정하면 돼요.

더 알아보기 (Learn more)

Upload 컴포넌트의 최신 API와 예시는 Arco Design 공식 문서에서 확인할 수 있어요.