Skip to content

Commit 9ed2592

Browse files
committed
add files2dataurl&fix error
1 parent 00116cd commit 9ed2592

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

chapter3/12_form_manipulation.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,24 @@ file.addEventListener(
284284
event.target.files, 0
285285
);
286286
files.forEach(function(item){
287-
files2dataurl(item. function(url){
287+
files2dataurl(item,function(url){
288288
var image = new Image();
289289
parent.appendChild(image);
290-
Image.src = url;
290+
image.src = url;
291291
});
292292
});
293293
}
294294
);
295+
function file2dataurl(file, callback) {
296+
if (!window.FileReader) {
297+
throw 'Browser not support File API !';
298+
}
299+
var reader = new FileReader();
300+
reader.readAsDataURL(file);
301+
reader.onload = function(event) {
302+
callback(event.target.result);
303+
};
304+
}
295305
```
296306

297307
NOTE:`accept` 所支持的格式有 `audio/*` `video/*` `image/*` 以及不带`;`的 MINE Type 类型和 `.` 开头的文件名后缀的文件。多个文件类型可以使用`,`分隔。

0 commit comments

Comments
 (0)