Top Banner
Files and Javascript DASHUKEVICH VLADIMIR 21.05.20 14
59

Files and JavaScript

Aug 22, 2015

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Files and JavaScript

Files and JavascriptDASHUKEVICH VLADIMIR

21.05.2014

Page 2: Files and JavaScript

Files like a forbidden fruit

Page 3: Files and JavaScript

What is a File in JS?

Page 4: Files and JavaScript

File and FileList API

Page 5: Files and JavaScript

What is a Blob?

Page 6: Files and JavaScript

Blob is a simple stuff)

Page 7: Files and JavaScript

What is a Blob?

Page 8: Files and JavaScript

How to get data from it?

Page 9: Files and JavaScript

We have to read them!

Page 10: Files and JavaScript

Use FileReader!

Page 11: Files and JavaScript

Read data as a text

Page 12: Files and JavaScript

File and FileReader support

Page 13: Files and JavaScript

How to get files from browser?

Page 14: Files and JavaScript

ActiveX as a solution

var ExcelSheet = new ActiveXObject("Excel.Sheet");

ExcelSheet.ActiveSheet.Cells(1,1).Value = "A";

ExcelSheet.SaveAs("C:\\TEST.XLS");

Page 15: Files and JavaScript

Ooooops!

Page 16: Files and JavaScript

NPAPI as a solution

Page 17: Files and JavaScript

You are really COOL!

Page 18: Files and JavaScript

How to get files from browser?

Page 19: Files and JavaScript

Input with “file“ type

Catch “drop“ event

CTRL+C -> CTRL+V

Get them from server

Page 20: Files and JavaScript

Input with “file“ type

1. <input type="file" />

2. Listen to “change”event

3. Look at “files“ property in IE10+ and other browsers.

Page 21: Files and JavaScript

<input type="file" multiple />

Page 22: Files and JavaScript

<input type="file" webkitdirectory />

Page 23: Files and JavaScript

Drag and drop

Page 24: Files and JavaScript

Drag and drop

Catch drop and dragover

Take a look at “dataTransfer” property of the event object

Page 25: Files and JavaScript

event.dataTransfer.files

Page 26: Files and JavaScript

event.dataTransfer.items

Page 27: Files and JavaScript

Webdrivers and Input Send custom drop event

Page 28: Files and JavaScript

Copy/paste

Page 29: Files and JavaScript

CTRL+C и CTRL+V (Chrome)

1.Catch “paste“ event2.Take a look at “clipboardData”

property

Page 30: Files and JavaScript

Copy XLS

Page 31: Files and JavaScript

CTRL+C and CTRL+V (All browsers)1. Create <div contenteditable ></div>2. Catch “paste“ event3. After timeout take the content from the

div element (base64)

Page 32: Files and JavaScript

You are awesome!!!

Page 33: Files and JavaScript

Get files from server

Page 34: Files and JavaScript

Get them from server

Page 35: Files and JavaScript

Drag me out of browser

1. Catch dragstart

2. Create a link and set it like with “setDate” method: e.dataTransfer.setData("DownloadURL", "application/pdf:doc.pdf:http://you.com");

Page 36: Files and JavaScript

Mythbusters(

Page 37: Files and JavaScript

The end is close)

Page 38: Files and JavaScript

What can we do with files on the client side?

Page 39: Files and JavaScript

Create a link to the files)

Page 40: Files and JavaScript

Parse XSL and XSLX files

XLS  - https://github.com/SheetJS/js-xls

XLSX - https://github.com/SheetJS/js-xlsx

Page 41: Files and JavaScript

XLSX.read(data, {type: 'binary'});

Page 42: Files and JavaScript

Browsers support

Browsers: IE6+ (base64)

Formats: ZIP, base64, binary, XLSX, XLSM, XLSB.

Page 43: Files and JavaScript

Data compression

Page 44: Files and JavaScript

JSZip

new JSZip(zipDataFromXHR, {base64:false});

Page 45: Files and JavaScript

zip.js

Safari 5 and IE9 (less than 4GB)

Page 46: Files and JavaScript

Parse PDF

Page 47: Files and JavaScript

PDF.js

https://github.com/mozilla/pdf.js

Page 48: Files and JavaScript

PDF.js

Page 49: Files and JavaScript

Other

Edit images

Edit sounds

Edit other formats

Page 50: Files and JavaScript

Saving files

Page 51: Files and JavaScript

Saving

1. Iframe with a link to the file (Chrome, FireFox)

2. execCommand (IE < 10) and msSaveOrOpenBlob(blob, defaultName);

3. localStorage4. indexDB

Page 52: Files and JavaScript

File System API

Page 53: Files and JavaScript
Page 54: Files and JavaScript
Page 55: Files and JavaScript

World without bugs

Page 56: Files and JavaScript

High salaries

Page 57: Files and JavaScript

Everything is great

Page 58: Files and JavaScript

Article

http://tinyurl.com/lusagk5

Page 59: Files and JavaScript

Your questions?