현재 번역은 완벽하지 않습니다. 한국어로 문서 번역에 동참해주세요.
요약
FileReader 객체는 웹 애플리케이션이 비동기적으로 파일을 구체화하거나 데이터를 읽기 위하여 File 혹은 Blob 객체를 이용해 파일의 내용을(혹은 raw data버퍼로) 읽고 사용자의 컴퓨터에 저장하는 것을 가능하게 해줍니다.
File 객체는 <input> 태그를 이용하여 유저가 선택한 파일들의 결과로서 반환된 FileList 객체, 드래그 앤 드랍으로 반환된 DataTransfer 객체 혹은 HTMLCanvasElement의 mozGetAsFile() API로 부터 얻는다.
생성자
FileReader FileReader();
파일들을 사용한 웹 애플리케이션의 사용 예제보기.
속성
FileReader.errorRead onlyDOMError파일을 읽는 도중에 발생한 에러를 나타냅니다.FileReader.readyStateRead onlyFileReader의 상태를 나타내는 숫자입니다. 이것은 State constants의 일종입니다.FileReader.resultRead only- 파일의 컨텐츠입니다. 이 속성은 읽기 작업이 완료되고 읽기 작업의 초기화에 사용한 방식으로 결정된 데이터의 포맷이 정해진 후에 유효합니다.
이벤트 핸들러
FileReader.onabortabort이벤트 핸들러. 이 이벤트는 읽기 동작이 중단 될 때 마다 발생합니다.FileReader.onerrorerror이벤트 핸들러. 이 이벤트는 읽기 동작이 에러를 마주할 때 마다 발생합니다.FileReader.onloadload이벤트 핸들러. 이 이벤트는 읽기 동작이 성공적으로 완료 되었을 때 마다 발생합니다.FileReader.onloadstartloadstart이벤트 핸들러. 이 이벤트는 읽기 동작이 실행 될 때 마다 발생합니다.FileReader.onloadendloadend이벤트 핸들러. 이 이벤트는 읽기 동작이 끝났을 때 마다 발생합니다. (읽기의 성공이나 실패 여부는 상관 않습니다.)FileReader.onprogressprogress이벤트 핸들러. 이 이벤트는Blob컨텐트를 읽는 동안 호출됩니다.
참고: FileReader는 EventTarget 으로 부터 상속 받았습니다, 언급된 모든 이벤트들은 addEventListener 메소드를 사용하여 listen 하게 할 수 있습니다.
상태 값들
EMPTY:0: 아직 데이터가 로드 되지 않았음.LOADING:1: 데이터가 로딩 중.DONE:2: 모든 읽기 요청이 완료됨.
메소드
FileReader.abort()- 읽기 요청을 중단 시킨다. 정상 리턴이 되며 readyState 는 DONE이 된다.
FileReader.readAsArrayBuffer()- Starts reading the contents of the specified
Blob, once finished, theresultattribute contains anArrayBufferrepresenting the file's data. FileReader.readAsBinaryString()- Starts reading the contents of the specified
Blob, once finished, theresultattribute contains the raw binary data from the file as a string. FileReader.readAsDataURL()- Starts reading the contents of the specified
Blob, once finished, theresultattribute contains adata:URL representing the file's data. FileReader.readAsText()- Starts reading the contents of the specified
Blob, once finished, theresultattribute contains the contents of the file as a text string.
Specifications
| Specification | Status | Comment |
|---|---|---|
| File API The definition of 'FileReader' in that specification. |
Working Draft | Initial definition. |
Browser compatibility
| Feature | Firefox (Gecko) | Chrome | Internet Explorer* | Opera* | Safari |
|---|---|---|---|---|---|
| Basic support | 3.6 (1.9.2) | 7 | 10 | 12.02 | 6.0.2 |
| Feature | Firefox Mobile (Gecko) | Android | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | 32 | 3 | 10 | 11.5 | 6.1 |
Implementation notes
- IE9 has a File API Lab.
- Opera has partial support in 11.1.
Gecko-specific notes
- Prior to Gecko 2.0 beta 7 (Firefox 4.0 beta 7), all
Blobparameters below wereFileparameters; this has since been updated to match the specification correctly. - Prior to Gecko 13.0 (Firefox 13.0 / Thunderbird 13.0 / SeaMonkey 2.10) the
FileReader.errorproperty returned aFileErrorobject. This interface has been removed andFileReader.erroris now returning theDOMErrorobject as defined in the latest FileAPI draft.
See also
- Using files from web applications
FileBlob- nsIDOMFileReader [en-US] - For addons/privelaged scope

