fileapi 2.0
DESCRIPTION
Разработка API для работы с файлами.TRANSCRIPT
![Page 1: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/1.jpg)
FileAPI: Загрузка и обработка файлов
![Page 2: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/2.jpg)
2
Что было
![Page 3: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/3.jpg)
3
Что было
![Page 4: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/4.jpg)
4
Что было
Flash
![Page 5: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/5.jpg)
5
Что было
HTML/JS
![Page 6: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/6.jpg)
6
• Множественный выбор файлов
• Получение информации (название, размер, тип)
• Создание пред-просмотра на клиенте
• Масштабирование, кадрирование и поворот
• Загрузка на сервер + CORS
Требования
![Page 7: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/7.jpg)
7
• Не зависеть от вёрстки
• Никакой бизнес-логики
• Расширяемость
• Самодостаточность
Требования
![Page 8: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/8.jpg)
![Page 9: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/9.jpg)
Error #2038
10%
![Page 10: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/10.jpg)
Error #2038
5%
![Page 11: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/11.jpg)
11
Поддержка
• Chrome 10+
• FireFox 3.6+
• Opera 11.1+
• Safari 5.4+
![Page 12: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/12.jpg)
12
![Page 13: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/13.jpg)
13
ПОЛУЧЕНИЕ СПИСКА
ФАЙЛОВ
![Page 14: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/14.jpg)
14
HTML5
<input id="file" type="file" multiple />
<script>
var input = document.getByElementId("file");
input.addEventListener("change", function (){
var files = input.files;
}, false);
</script>
![Page 15: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/15.jpg)
15
HTML5
<input id="file" type="file" multiple />
<script>
var input = document.getByElementId("file");
input.addEventListener("change", function (){
var files = input.files;
}, false);
</script>
![Page 16: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/16.jpg)
16
HTML5
<input id="file" type="file" multiple />
<script>
var input = document.getByElementId("file");
input.addEventListener("change", function (){
var files = input.files;
}, false);
</script>
![Page 17: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/17.jpg)
17
Flash
FLASH
![Page 18: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/18.jpg)
18
Flash
FLASH
![Page 19: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/19.jpg)
19
Flash
FLASH
Flash --> jsFunc([{
id: "346515436346", // уникальный идентификатор
name: "hello-world.png", // название файла
type: "image/png", // mime-type
size: 43325 // рамер
}, {
// etc.
}])
![Page 20: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/20.jpg)
Взаимодействие
flash.cmd("imageTransform", {
id: "346515436346", // идентификатор файла
matrix: { }, // "матрица" трансформации
callback: "__UNIQ_NAME__" // размер
});
![Page 21: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/21.jpg)
21
API
<span class="js-fileapi-wrapper" style="position: relative">
<input id="file" type="file" multiple />
</span>
<script>
var input = document.getByElementId("file");
FileAPI.event.on(input, "change", function (){
var files = FileAPI.getFiles(input);
});
</script>
![Page 22: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/22.jpg)
22
API
<span class="js-fileapi-wrapper" style="position: relative">
<input id="file" type="file" multiple />
</span>
<script>
var input = document.getByElementId("file");
FileAPI.event.on(input, "change", function (evt){
var files = FileAPI.getFiles(evt);
});
</script>
![Page 23: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/23.jpg)
23
ФИЛЬТРАЦИЯ
![Page 24: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/24.jpg)
FileReader
• readAsDataURL(file)
• readAsArrayBuffer(file)
• readAsText(file[, encoding])
![Page 25: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/25.jpg)
25
Фильтрация
FileAPI.filterFiles(files, function (file, info){
return file.size < 10 * FileAPI.MB;
}, function (files, ignore){
if( files.length > 0 ){
// ...
}
});
![Page 26: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/26.jpg)
FileAPI.getInfo(audioFile, function (err, tags){
if( !err ){
var li = document.createElement("li");
li.innerHTML = tags.artist +" – "+ tags.title;
ul.appendChild(li);
}
});
Информация о файле
![Page 27: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/27.jpg)
ПРЕДПРОСМОТР
![Page 28: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/28.jpg)
Предпросмотр
DataURI
![Page 29: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/29.jpg)
Предпросмотр
DataURI
Base64
![Page 30: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/30.jpg)
Предпросмотр
DataURI
Base64
“data:image/png;base64,” + Base64
<img/>
![Page 31: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/31.jpg)
Предпросмотр
DataURI
Base64
“data:image/png;base64,” + Base64
<img/>
![Page 32: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/32.jpg)
Предпросмотр
HTML5
• FileReader.readAsDataURL(file) — позволяет
прочесть содержимое файла как DataURL
• URL.createObjectURL(file) — создает ссылку,
указывающую на файл
![Page 33: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/33.jpg)
Предпросмотр
HTML5
• FileReader.readAsDataURL(file) — позволяет
прочесть содержимое файла как DataURL
• URL.createObjectURL(file) — создает ссылку,
указывающую на файл
• URL.revokeObjectURL(file) — убрать ссылку
![Page 34: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/34.jpg)
34
• crop(x, y, width, height) — кадрирование
• resize(width[, height]) — масштабирование
• rotate(deg) — поворот
• preview(width, height) — кадрирует и масштабирует
• get(callback) — получить итоговое изображение
FileAPI.Image
![Page 35: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/35.jpg)
35
Matrix
{ // параметры фрагмента оригинала
sx: Number,
sy: Number,
sw: Number,
sh: Number,
// требуемые размеры
dw: Number,
dh: Number,
deg: Number
}
![Page 36: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/36.jpg)
36
FileAPI.Image
FileAPI.Image(imageFle)
.crop(300, 300)
.resize(100, 100)
.get(function (err, img){
if( !err ){
images.appendChild(img);
}
})
;
![Page 37: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/37.jpg)
Сжатие
5197х4987
![Page 38: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/38.jpg)
Сжатие
![Page 39: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/39.jpg)
Сжатие
5197х4987 2598х2493
![Page 40: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/40.jpg)
Сжатие x 2
5197х4987 2598х2493 1299х1246
![Page 41: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/41.jpg)
Сжатие x 5
5197х4987 2598х2493 1299х1246
100х100
![Page 42: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/42.jpg)
Сжатие
Серия
![Page 43: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/43.jpg)
ЗАГРУЗКА ФАЙЛОВ
![Page 44: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/44.jpg)
Загрузка
<form
action="/upload"
method="post"
enctype="multipart/form-data">
<input name="files" type="file" />
<input name="foo" value="bar" type="hidden" />
</form>
![Page 45: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/45.jpg)
Загрузка
<form
target="__UNIQ__"
action="/upload"
method="post"
enctype="multipart/form-data">
<iframe name="__UNIQ__"></iframe>
<input name="files" type="file" />
<input name="foo" value="bar" type="hidden" />
</form>
Уникальный идентификатор
![Page 46: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/46.jpg)
Загрузка
XMLHttpRequest level 2
FormData
![Page 47: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/47.jpg)
Загрузка
// собираем данные для отправки
var form = new FormData
form.append("foo", "bar");
form.append("attach", file);
// отправояем на сервер
var xhr = new XMLHttpRequest;
xhr.open("POST", "/upload", true);
xhr.send(form)
![Page 48: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/48.jpg)
Загрузка
// собираем данные для отправки
var form = new FormData
form.append("foo", "bar");
form.append("attach", file);
// отправояем на сервер
var xhr = new XMLHttpRequest;
xhr.open("POST", "/upload", true);
xhr.send(form)
![Page 49: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/49.jpg)
Загрузка
canvasToBlob(canvas, function (blob){
// собираем данные для отправки
var form = new FormData
form.append("foo", "bar");
form.append("attach", blob, "filename.png");
// отправляем на сервер
var xhr = new XMLHttpRequest;
xhr.open("POST", "/upload", true);
xhr.send(form)
});
![Page 50: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/50.jpg)
Загрузка
<cavnas/> DataURL
dataURL = canvas.toDataURL(“image/png”);
![Page 51: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/51.jpg)
Загрузка
<cavnas/> DataURL Base64
dataURL = canvas.toDataURL(“image/png”);
base64 = dataURL.replace(/^data:[^,]+,/, “”);
![Page 52: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/52.jpg)
Загрузка
<cavnas/> DataURL Base64
BinaryString
dataURL = canvas.toDataURL(“image/png”);
base64 = dataURL.replace(/^data:[^,]+,/, “”);
binaryString = window.atob(base64);
![Page 53: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/53.jpg)
53
Multipart
var uniq = '1234567890';
var xhr = new XMLHttpRequest;
xhr.open('POST', '/upload', true);
xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=_'+uniq);
xhr.sendAsBinary([
'--_'+ uniq
, 'Content-Disposition: form-data; name="my-file"; filename="hello-world.png"'
, 'Content-Type: image/png'
, ''
, binaryString
, '--_'+ uniq +'--'
].join('\r\n'));
![Page 54: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/54.jpg)
54
Загрузка
var xhr = FileAPI.upload({
url: '/upload',
data: { foo: 'bar' },
headers: { 'Session-Id': '...' },
files: { images: imageFiles, others: otherFiles },
imageTransform: { maxWidth: 1024, maxHeight: 768 },
upload: function (xhr){},
progress: function (event, file){},
complete: function (err, xhr, file){},
fileupload: function (file, xhr){},
fileprogress: function (event, file){},
filecomplete: function (err, xhr, file){}
});
![Page 55: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/55.jpg)
55
var xhr = FileAPI.upload({
url: '/upload',
data: { foo: 'bar' },
headers: { 'Session-Id': '...' },
files: { images: imageFiles, others: otherFiles },
imageTransform: { maxWidth: 1024, maxHeight: 768 },
upload: function (xhr){},
progress: function (event, file){},
complete: function (err, xhr, file){},
fileupload: function (file, xhr){},
fileprogress: function (event, file){},
filecomplete: function (err, xhr, file){}
});
Загрузка
![Page 56: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/56.jpg)
Загрузка
{
huge: { maxWidth: 800, maxHeight: 600, rotate: 90 },
medium: { width: 320, height: 240, preview: true },
small: { width: 100, height: 120, preview: true }
}
imageTransform:
![Page 57: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/57.jpg)
57
XHR
var xhr = FileAPI.upload({ … });
![Page 58: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/58.jpg)
58
XHR
var xhr = FileAPI.upload({ … });
• status — HTTP status code
• statusText — HTTP status text
• responseText — ответ сервера
• getResponseHeader(name) — получить заголовок ответа сервера
• getAllResponseHeaders() — получить все заголовки
• abort() — отменить загрузку
![Page 59: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/59.jpg)
Drag’n’Drop
Перетащите файлы сюда
<div class="dropzone"></div>
![Page 60: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/60.jpg)
Drag’n’Drop
4
<div class="dropzone dropzone_hover"></div>
![Page 61: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/61.jpg)
Drag’n’Drop
<div id="el" class="dropzone"></div>
<script>
var el = document.getElementById("el");
FileAPI.event.dnd(el, function (over){
if( ever ){
el.classList.add("dropzone_hover");
} else {
el.classList.remove("dropzone_hover");
}
}, function (files){
uploadFiles(files);
});
</script>
4
![Page 62: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/62.jpg)
Drag’n’Drop
<div id="el" class="dropzone"></div>
<script>
var el = document.getElementById("el");
FileAPI.event.dnd(el, function (over){
if( ever ){
el.classList.add("dropzone_hover");
} else {
el.classList.remove("dropzone_hover");
}
}, function (files){
uploadFiles(files);
});
</script>
4
![Page 63: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/63.jpg)
Drag’n’Drop
<div id="el" class="dropzone"></div>
<script>
var el = document.getElementById("el");
FileAPI.event.dnd(el, function (over){
if( ever ){
el.classList.add("dropzone_hover");
} else {
el.classList.remove("dropzone_hover");
}
}, function (files){
uploadFiles(files);
});
</script>
4
![Page 64: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/64.jpg)
Drag’n’Drop
<div id="el" class="dropzone"></div>
<script>
var el = document.getElementById("el");
FileAPI.event.dnd(el, function (over){
if( ever ){
el.classList.add("dropzone_hover");
} else {
el.classList.remove("dropzone_hover");
}
}, function (files){
uploadFiles(files);
});
</script>
4
![Page 65: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/65.jpg)
Drag’n’Drop
function uploadFiles(dropFiles){
FileAPI.upload({
url: "/upload",
files: { attaches: dropFiles },
complete: function (err, xhr){
if( !err ){
// файлы загружены
}
}
});
}
4
![Page 66: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/66.jpg)
Спустя год
• Закрыто более 100 github issue
• GruntJS (JSLint, QUnit + PhantomJS, Uglify)
• Улучшена работа с изображениями
• Добавлена поддержка работы с веб-камерой
• Разработан jQuery plugin для типовых задач
• Улучшена документация (+ примеры)
![Page 67: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/67.jpg)
OVERLAYS
![Page 68: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/68.jpg)
Overlay
FileAPI.Image(imageFile)
.overlay([{
x: 10
, y: 10
, src: "/i/watermark.png"
, rel: FileAPI.Image.RITGHT_BOTTOM
, opacity: 0.85
])
.get(function (err/**String*/, img/**HTMLElement*/)({ /*__*/ })
;
![Page 69: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/69.jpg)
Overlay
var xhr = FileAPI.upload({
url: "...",
files: images,
imageTransform: {
overlay: { /* options */ }
}
});
![Page 70: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/70.jpg)
FILTERS
![Page 71: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/71.jpg)
Filters
FileAPI.Image(imageFile)
.filter(function (canvas, doneFn){
// processing...
doneFn();
})
.get(function (err/**String*/, img/**HTMLElement*/)({
/*__*/
})
;
![Page 72: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/72.jpg)
CamanJS
![Page 73: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/73.jpg)
Filters + CamanJS
FileAPI.Image(imageFile)
.filter("hazyDays")
.get(function (err/**String*/,
img/**HTMLElement*/)({
/*__*/
})
;
![Page 74: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/74.jpg)
WebCam
![Page 75: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/75.jpg)
WebCam
navigator.getUserMedia( constraints, success, error );
— запросить разрешение на использование
микрофона и/или камеры
![Page 76: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/76.jpg)
WebCam
navigator.getUserMedia({ video: true }, function (stream){
var video = document.getElementById("webcam");
var streamSrc = URL.createObjectURL(stream);
video.src = streamUrl;
});
![Page 77: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/77.jpg)
WebCam
navigator.getUserMedia({ video: true }, function (stream){
var video = document.getElementById("webcam");
var streamSrc = URL.createObjectURL(stream);
video.src = streamUrl;
});
![Page 78: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/78.jpg)
WebCam
function onTakeShot(){
var video = document.getElementById("webcam");
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
ctx.drawImage(video, 0, 0);
}
![Page 79: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/79.jpg)
FileAPI.Camera
var el = document.getElementById("webcam");
FileAPI.Camera.publish(el, function (cam){
});
![Page 80: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/80.jpg)
FileAPI.Camera
var el = document.getElementById("webcam");
FileAPI.Camera.publish(el, function (cam){
FileAPI.event.on(btn, "click", function (){
var shot = cam.shot(); // FileAPI.Image instance
FileAPI.upload({ url: "...", files: shot });
});
});
![Page 81: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/81.jpg)
jQuery.FileAPI
• «Одной кнопкой» — выбрать и автоматически загрузить файл
• «Ограничения» — минимальный/максимальный размер как
файла, так и изображения, по ширине и высоте
• «Работа с очередью» — сортировка и фильтрация очереди
загрузки файлов
• «Изображения» — предпросмотр, поворот и кадрирование
• «Интерфейс» — гибкая и прозрачная настройка интерфейса
• А также Drag’n’Drop и WebCam
![Page 82: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/82.jpg)
jQuery.FileAPI
![Page 83: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/83.jpg)
jQuery.FileAPI
![Page 84: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/84.jpg)
jQuery.FileAPI
![Page 85: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/85.jpg)
jQuery.FileAPI
![Page 86: FileAPI 2.0](https://reader034.vdocuments.mx/reader034/viewer/2022042816/559b0bbb1a28abbd638b462a/html5/thumbnails/86.jpg)
jQuery.FileAPI