aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/api/filereader/readasdataurl
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:17 -0500
commitda78a9e329e272dedb2400b79a3bdeebff387d47 (patch)
treee6ef8aa7c43556f55ddfe031a01cf0a8fa271bfe /files/ko/web/api/filereader/readasdataurl
parent1109132f09d75da9a28b649c7677bb6ce07c40c0 (diff)
downloadtranslated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.gz
translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.bz2
translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.zip
initial commit
Diffstat (limited to 'files/ko/web/api/filereader/readasdataurl')
-rw-r--r--files/ko/web/api/filereader/readasdataurl/index.html171
1 files changed, 171 insertions, 0 deletions
diff --git a/files/ko/web/api/filereader/readasdataurl/index.html b/files/ko/web/api/filereader/readasdataurl/index.html
new file mode 100644
index 0000000000..1533dc620d
--- /dev/null
+++ b/files/ko/web/api/filereader/readasdataurl/index.html
@@ -0,0 +1,171 @@
+---
+title: FileReader.readAsDataURL()
+slug: Web/API/FileReader/readAsDataURL
+translation_of: Web/API/FileReader/readAsDataURL
+---
+<div>{{APIRef("File API")}}</div>
+
+<p> </p>
+
+<p><code>readAsDataURL</code> 메서드는 컨텐츠를 특정 {{domxref("Blob")}} 이나 {{domxref("File")}}에서 읽어 오는 역할을 합니다. 읽어오는 read 행위가 종료되는 경우에, {{domxref("FileReader.readyState","readyState")}} 의 상태가 <code>DONE</code>이 되며,   {{event("loadend")}} 이벤트가 트리거 됩니다. 이와 함께,  base64 인코딩 된 스트링 데이터가 {{domxref("FileReader.result","result")}}  속성(attribute)에 담아지게 됩니다.</p>
+
+<h2 id="문법">문법</h2>
+
+<pre class="syntaxbox"><em>instanceOfFileReader</em>.readAsDataURL(blob);</pre>
+
+<h3 id="파라미터">파라미터</h3>
+
+<dl>
+ <dt><code>blob</code></dt>
+ <dd>읽고자 하는 {{domxref("Blob")}} 또는 {{domxref("File")}}.</dd>
+</dl>
+
+<h2 id="예제">예제</h2>
+
+<h3 id="HTML">HTML</h3>
+
+<pre class="brush: html">&lt;input type="file" onchange="previewFile()"&gt;&lt;br&gt;
+&lt;img src="" height="200" alt="이미지 미리보기..."&gt;</pre>
+
+<h3 id="JavaScript">JavaScript</h3>
+
+<pre class="brush: js">function previewFile() {
+  var preview = document.querySelector('img');
+  var file    = document.querySelector('input[type=file]').files[0];
+  var reader  = new FileReader();
+
+  reader.addEventListener("load", function () {
+    preview.src = reader.result;
+  }, false);
+
+  if (file) {
+    reader.readAsDataURL(file);
+  }
+}</pre>
+
+<h3 id="실행_결과">실행 결과</h3>
+
+<p>{{EmbedLiveSample("Example", "100%", 240)}}</p>
+
+<p> </p>
+
+<h2 id="복수의_파일_읽기_예제">복수의 파일 읽기 예제</h2>
+
+<h3 id="HTML_2">HTML</h3>
+
+<pre class="brush: html">&lt;input id="browse" type="file" onchange="previewFiles()" multiple&gt;
+&lt;div id="preview"&gt;&lt;/div&gt;</pre>
+
+<h3 id="JavaScript_2">JavaScript</h3>
+
+<pre class="brush: js">function previewFiles() {
+
+ var preview = document.querySelector('#preview');
+ var files = document.querySelector('input[type=file]').files;
+
+ function readAndPreview(file) {
+
+ // `file.name` 형태의 확장자 규칙에 주의하세요
+ if ( /\.(jpe?g|png|gif)$/i.test(file.name) ) {
+ var reader = new FileReader();
+
+ reader.addEventListener("load", function () {
+ var image = new Image();
+ image.height = 100;
+ image.title = file.name;
+ image.src = this.result;
+ preview.appendChild( image );
+ }, false);
+
+ reader.readAsDataURL(file);
+ }
+
+ }
+
+ if (files) {
+ [].forEach.call(files, readAndPreview);
+ }
+
+}
+</pre>
+
+<div class="note"><strong>주의:</strong> <a href="/en-US/docs/Web/API/FileReader"><code>FileReader()</code></a> 생성자는 Internet Explorer 10 이전 버전에서는 지원하지 않는 기능입니다. 정상적으로 지원하는 코드를 확인하기 위해서는 다음 링크를 참조하시기 바랍니다. <a class="internal" href="https://mdn.mozillademos.org/files/3699/crossbrowser_image_preview.html" title="crossbrowser_image_preview.html">crossbrowser possible solution for image preview</a>. 또는 <a href="https://mdn.mozillademos.org/files/3698/image_upload_preview.html">this more powerful example</a>.</div>
+
+<h2 id="명세">명세</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">명세</th>
+ <th scope="col">상태</th>
+ <th scope="col">비고</th>
+ </tr>
+ <tr>
+ <td>{{SpecName("File API", "#FileReader-interface", "FileReader")}}</td>
+ <td>{{Spec2("File API")}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="브라우저_호환성">브라우저 호환성</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Firefox (Gecko)</th>
+ <th>Chrome</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatGeckoDesktop("1.9.2")}}<sup>[1]</sup></td>
+ <td>7</td>
+ <td>10<sup>[2]</sup></td>
+ <td>12.02<sup>[3]</sup></td>
+ <td>6.0</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Android</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>32</td>
+ <td>3</td>
+ <td>10</td>
+ <td>11.5</td>
+ <td>6.0</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] Prior to Gecko 2.0 beta 7 (Firefox 4.0 beta 7), all {{domxref("Blob")}} parameters below were {{domxref("File")}} parameters; this has since been updated to match the specification correctly. Prior to Gecko 13.0 {{geckoRelease("13.0")}} the <code>FileReader.error</code> property returned a {{domxref("FileError")}} object. This interface has been removed and <code>FileReader.error</code> is now returning the {{domxref("DOMError")}} object as defined in the latest FileAPI draft.</p>
+
+<p>[2] IE9 has a <a href="http://html5labs.interoperabilitybridges.com/prototypes/fileapi/fileapi/info">File API Lab</a>.</p>
+
+<p>[3] Opera has <a href="http://www.opera.com/docs/specs/presto28/file/">partial support</a> in 11.1.</p>
+
+<h2 id="바깥_고리">바깥 고리</h2>
+
+<ul>
+ <li>{{domxref("FileReader")}}</li>
+</ul>