SlideShare a Scribd company logo
Jason
INTRODUCTION
 The File API could be used to create a
thumbnail preview of images as they're
being sent to the server, or allow an app
to save a file reference while the user is
offline.
Browser Support
 File API are supported in all major
browsers. except Internet Explorer.
 Resources:http://caniuse.com/fileapi
File API
 Blob - Allows for slicing a file into byte ranges.
 File
 FileReader
File API - Blob
var b = new Blob() ;
var b =new Blob(['AAA', 'BBB'],{ 'type': 'text/plain'}) ;
b.type
b.size.
b.slice(start, length)
File API - File
 var file = $(“input[type=file]")[0].files[0];
 file.name
 file.type
 file.size.
 file.slice(start, length)
File API - FileReader
 FileReader.readAsBinaryString(Blob|File)
 The result property will contain the file/blob's
data as a binary string. Every byte is
represented by an integer in the range [0..255].
File API - FileReader
 FileReader.readAsText(Blob|File, opt_encoding)
 The result property will contain the file/blob's
data as a text string. By default the string is
decoded as 'UTF-8'. Use the optional encoding
parameter can specify a different format.
File API - FileReader
 FileReader.readAsDataURL(Blob|File)
 The result property will contain the file/blob's
data encoded as a data URL
Data URI scheme
 http URI scheme
 <img src="http://www.hkpug.net/files/images/check.png"/>
 data URI scheme
 <img
src="data:image/png;base64,iVBORw0KGgoAAAANS
UhEUgAAAAQAAAADCAIAAAA
7ljmRAAAAGElEQVQIW2P4DwcMDAxAfBvMAhEQM
YgcACEHG8ELxtbPAAAAAElFTkSuQmCC" />
Data URI scheme
 data:image/png;base64,iVBORw0KGgoAAAANSUh
EUgAAAAQAAAADCAIAAAA
7ljmRAAAAGElEQVQIW2P4DwcMDAxAfBvMAhEQ
MYgcACEHG8ELxtbPAAAAAElFTkSuQmCC
 data - 取得 data 的協定名稱
 image/png – data 類型名稱
 base64 – data 的編碼方法
 iVBOR.... - 編碼後的 data
 : , ; - data URI scheme 指定的分隔符號
Data URI scheme
 Data URI scheme 也可以在 CSS 中使用,例
如:
 body { background-image:
url("data:image/png;base64,iVBORw0KGgoAA
AANSUhEUgAAAAQAAAADCAIAAAA
7ljmRAAAAGElEQVQIW2P4DwcMDAxAfBvM
AhEQMYgcACEHG8ELxtbPAAAAAElFTkSuQ
mCC");}
File API - FileReader
 FileReader.onloadstart // 讀取操作開始時觸發
 FileReader.onprogress // 讀取操作過程中觸發
 FileReader.onabort // 讀取操作被中斷時觸發
 FileReader.onerror // 讀取操作失敗時觸發
 FileReader.onload // 讀取操作成功時觸發
 FileReader.onloadend // 讀取操作完成時觸發
(不論成功還是失敗)
File API – FileReader States
 FileReader.EMPTY (Value = 0):
No data has been loaded yet.
 FileReader.LOADING (Value = 1):
Data is currently being loaded
 FileReader.DONE (Vlaue = 2):
The entire read request has been
completed.
File API - Example
var file = $("#file")[0].files[0];
var reader = new FileReader();
reader.readAsText (file);
reader.onload = function(){
$("#content").val(reader.result);
};
File API - Blob
var file = new Blob(
["這是建立 Blob 的內容!!"],
{ "type": "text/plain" });
var fileReader = new FileReader();
fileReader.onload = function (event) {
console.log('新建 Blob 檔案內容:'+this.result);
} ;
fileReader.readAsText(file);
Reference
 http://www.w3.org/TR/file-upload/#dfn-
Blob
 http://www.w3.org/TR/FileAPI/#dfn-file

More Related Content

Viewers also liked

T sql語法之 cte 20140214
T sql語法之 cte 20140214T sql語法之 cte 20140214
T sql語法之 cte 20140214LearningTech
 
Query string httpvaluecollection
Query string httpvaluecollectionQuery string httpvaluecollection
Query string httpvaluecollectionLearningTech
 
Auto fac mvc以及進階應用(一)
Auto fac mvc以及進階應用(一)Auto fac mvc以及進階應用(一)
Auto fac mvc以及進階應用(一)LearningTech
 
Implement custom iprincipal in mvc
Implement custom iprincipal in mvcImplement custom iprincipal in mvc
Implement custom iprincipal in mvcLearningTech
 
20120518 advanced jsrendertemplatingfeatures
20120518 advanced jsrendertemplatingfeatures20120518 advanced jsrendertemplatingfeatures
20120518 advanced jsrendertemplatingfeaturesLearningTech
 
20131108 boot strap-basiccss By Randy
20131108 boot strap-basiccss By Randy20131108 boot strap-basiccss By Randy
20131108 boot strap-basiccss By RandyLearningTech
 

Viewers also liked (8)

T sql語法之 cte 20140214
T sql語法之 cte 20140214T sql語法之 cte 20140214
T sql語法之 cte 20140214
 
Query string httpvaluecollection
Query string httpvaluecollectionQuery string httpvaluecollection
Query string httpvaluecollection
 
Js types
Js typesJs types
Js types
 
Auto fac mvc以及進階應用(一)
Auto fac mvc以及進階應用(一)Auto fac mvc以及進階應用(一)
Auto fac mvc以及進階應用(一)
 
Implement custom iprincipal in mvc
Implement custom iprincipal in mvcImplement custom iprincipal in mvc
Implement custom iprincipal in mvc
 
20120518 advanced jsrendertemplatingfeatures
20120518 advanced jsrendertemplatingfeatures20120518 advanced jsrendertemplatingfeatures
20120518 advanced jsrendertemplatingfeatures
 
20131108 boot strap-basiccss By Randy
20131108 boot strap-basiccss By Randy20131108 boot strap-basiccss By Randy
20131108 boot strap-basiccss By Randy
 
Html basic
Html basicHtml basic
Html basic
 

Similar to File api

Configuring Greenstone's OAI server
Configuring Greenstone's OAI serverConfiguring Greenstone's OAI server
Configuring Greenstone's OAI serverDiego Spano
 
Going on an HTTP Diet: Front-End Web Performance
Going on an HTTP Diet: Front-End Web PerformanceGoing on an HTTP Diet: Front-End Web Performance
Going on an HTTP Diet: Front-End Web PerformanceAdam Norwood
 
Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC FrameworkBala Kumar
 
HTTP/2 What's inside and Why
HTTP/2 What's inside and WhyHTTP/2 What's inside and Why
HTTP/2 What's inside and WhyAdrian Cole
 
Azure Blob Storage API for Scala and Spark
Azure Blob Storage API for Scala and SparkAzure Blob Storage API for Scala and Spark
Azure Blob Storage API for Scala and SparkBraja Krishna Das
 
Web development - technologies and tools
Web development - technologies and toolsWeb development - technologies and tools
Web development - technologies and toolsYoann Gotthilf
 
Spring Boot with Microsoft Azure Integration.pdf
Spring Boot with Microsoft Azure Integration.pdfSpring Boot with Microsoft Azure Integration.pdf
Spring Boot with Microsoft Azure Integration.pdfInexture Solutions
 
The new static resources framework
The new static resources frameworkThe new static resources framework
The new static resources frameworkmarcplmer
 
cdac@parag.gajbhiye@test123
cdac@parag.gajbhiye@test123cdac@parag.gajbhiye@test123
cdac@parag.gajbhiye@test123Parag Gajbhiye
 
SP Rest API Documentation
SP Rest API DocumentationSP Rest API Documentation
SP Rest API DocumentationIT Industry
 
Web Technologies (2/12): Web Programming – HTTP. Cookies. Web Sessions
Web Technologies (2/12): Web Programming – HTTP. Cookies. Web SessionsWeb Technologies (2/12): Web Programming – HTTP. Cookies. Web Sessions
Web Technologies (2/12): Web Programming – HTTP. Cookies. Web SessionsSabin Buraga
 
Posting Images using Android
Posting Images using AndroidPosting Images using Android
Posting Images using AndroidAli Muzaffar
 
BioCASE web services for germplasm data sets, at FAO, Rome (2006)
BioCASE web services for germplasm data sets, at FAO, Rome (2006)BioCASE web services for germplasm data sets, at FAO, Rome (2006)
BioCASE web services for germplasm data sets, at FAO, Rome (2006)Dag Endresen
 
Seguranca em APP Rails
Seguranca em APP RailsSeguranca em APP Rails
Seguranca em APP RailsDaniel Lopes
 
Video Archiving and Playback in the Wayback Machine
Video Archiving and Playback in the Wayback MachineVideo Archiving and Playback in the Wayback Machine
Video Archiving and Playback in the Wayback MachineSawood Alam
 
File uploading through paperclip in rails 3.x
File uploading through paperclip in rails 3.xFile uploading through paperclip in rails 3.x
File uploading through paperclip in rails 3.xAndolasoft Inc
 
Web Standards Support in WebKit
Web Standards Support in WebKitWeb Standards Support in WebKit
Web Standards Support in WebKitJoone Hur
 

Similar to File api (20)

Apache Kite
Apache KiteApache Kite
Apache Kite
 
Configuring Greenstone's OAI server
Configuring Greenstone's OAI serverConfiguring Greenstone's OAI server
Configuring Greenstone's OAI server
 
Html5 Basic Structure
Html5 Basic StructureHtml5 Basic Structure
Html5 Basic Structure
 
Going on an HTTP Diet: Front-End Web Performance
Going on an HTTP Diet: Front-End Web PerformanceGoing on an HTTP Diet: Front-End Web Performance
Going on an HTTP Diet: Front-End Web Performance
 
Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC Framework
 
HTTP/2 What's inside and Why
HTTP/2 What's inside and WhyHTTP/2 What's inside and Why
HTTP/2 What's inside and Why
 
Azure Blob Storage API for Scala and Spark
Azure Blob Storage API for Scala and SparkAzure Blob Storage API for Scala and Spark
Azure Blob Storage API for Scala and Spark
 
Web development - technologies and tools
Web development - technologies and toolsWeb development - technologies and tools
Web development - technologies and tools
 
Spring Boot with Microsoft Azure Integration.pdf
Spring Boot with Microsoft Azure Integration.pdfSpring Boot with Microsoft Azure Integration.pdf
Spring Boot with Microsoft Azure Integration.pdf
 
The new static resources framework
The new static resources frameworkThe new static resources framework
The new static resources framework
 
cdac@parag.gajbhiye@test123
cdac@parag.gajbhiye@test123cdac@parag.gajbhiye@test123
cdac@parag.gajbhiye@test123
 
SP Rest API Documentation
SP Rest API DocumentationSP Rest API Documentation
SP Rest API Documentation
 
Web Technologies (2/12): Web Programming – HTTP. Cookies. Web Sessions
Web Technologies (2/12): Web Programming – HTTP. Cookies. Web SessionsWeb Technologies (2/12): Web Programming – HTTP. Cookies. Web Sessions
Web Technologies (2/12): Web Programming – HTTP. Cookies. Web Sessions
 
Posting Images using Android
Posting Images using AndroidPosting Images using Android
Posting Images using Android
 
BioCASE web services for germplasm data sets, at FAO, Rome (2006)
BioCASE web services for germplasm data sets, at FAO, Rome (2006)BioCASE web services for germplasm data sets, at FAO, Rome (2006)
BioCASE web services for germplasm data sets, at FAO, Rome (2006)
 
Seguranca em APP Rails
Seguranca em APP RailsSeguranca em APP Rails
Seguranca em APP Rails
 
Video Archiving and Playback in the Wayback Machine
Video Archiving and Playback in the Wayback MachineVideo Archiving and Playback in the Wayback Machine
Video Archiving and Playback in the Wayback Machine
 
File uploading through paperclip in rails 3.x
File uploading through paperclip in rails 3.xFile uploading through paperclip in rails 3.x
File uploading through paperclip in rails 3.x
 
Php frameworks
Php frameworksPhp frameworks
Php frameworks
 
Web Standards Support in WebKit
Web Standards Support in WebKitWeb Standards Support in WebKit
Web Standards Support in WebKit
 

More from LearningTech

More from LearningTech (20)

vim
vimvim
vim
 
PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection &amp; activator
Reflection &amp; activatorReflection &amp; activator
Reflection &amp; activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 

Recently uploaded

Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlPeter Udo Diehl
 
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»QADay
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...Elena Simperl
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsExpeed Software
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform EngineeringJemma Hussein Allen
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Product School
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1DianaGray10
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoTAnalytics
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Thierry Lestable
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsPaul Groth
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxDavid Michel
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...Sri Ambati
 

Recently uploaded (20)

Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

File api

  • 2. INTRODUCTION  The File API could be used to create a thumbnail preview of images as they're being sent to the server, or allow an app to save a file reference while the user is offline.
  • 3. Browser Support  File API are supported in all major browsers. except Internet Explorer.  Resources:http://caniuse.com/fileapi
  • 4. File API  Blob - Allows for slicing a file into byte ranges.  File  FileReader
  • 5. File API - Blob var b = new Blob() ; var b =new Blob(['AAA', 'BBB'],{ 'type': 'text/plain'}) ; b.type b.size. b.slice(start, length)
  • 6. File API - File  var file = $(“input[type=file]")[0].files[0];  file.name  file.type  file.size.  file.slice(start, length)
  • 7. File API - FileReader  FileReader.readAsBinaryString(Blob|File)  The result property will contain the file/blob's data as a binary string. Every byte is represented by an integer in the range [0..255].
  • 8. File API - FileReader  FileReader.readAsText(Blob|File, opt_encoding)  The result property will contain the file/blob's data as a text string. By default the string is decoded as 'UTF-8'. Use the optional encoding parameter can specify a different format.
  • 9. File API - FileReader  FileReader.readAsDataURL(Blob|File)  The result property will contain the file/blob's data encoded as a data URL
  • 10. Data URI scheme  http URI scheme  <img src="http://www.hkpug.net/files/images/check.png"/>  data URI scheme  <img src="data:image/png;base64,iVBORw0KGgoAAAANS UhEUgAAAAQAAAADCAIAAAA 7ljmRAAAAGElEQVQIW2P4DwcMDAxAfBvMAhEQM YgcACEHG8ELxtbPAAAAAElFTkSuQmCC" />
  • 11. Data URI scheme  data:image/png;base64,iVBORw0KGgoAAAANSUh EUgAAAAQAAAADCAIAAAA 7ljmRAAAAGElEQVQIW2P4DwcMDAxAfBvMAhEQ MYgcACEHG8ELxtbPAAAAAElFTkSuQmCC  data - 取得 data 的協定名稱  image/png – data 類型名稱  base64 – data 的編碼方法  iVBOR.... - 編碼後的 data  : , ; - data URI scheme 指定的分隔符號
  • 12. Data URI scheme  Data URI scheme 也可以在 CSS 中使用,例 如:  body { background-image: url("data:image/png;base64,iVBORw0KGgoAA AANSUhEUgAAAAQAAAADCAIAAAA 7ljmRAAAAGElEQVQIW2P4DwcMDAxAfBvM AhEQMYgcACEHG8ELxtbPAAAAAElFTkSuQ mCC");}
  • 13. File API - FileReader  FileReader.onloadstart // 讀取操作開始時觸發  FileReader.onprogress // 讀取操作過程中觸發  FileReader.onabort // 讀取操作被中斷時觸發  FileReader.onerror // 讀取操作失敗時觸發  FileReader.onload // 讀取操作成功時觸發  FileReader.onloadend // 讀取操作完成時觸發 (不論成功還是失敗)
  • 14. File API – FileReader States  FileReader.EMPTY (Value = 0): No data has been loaded yet.  FileReader.LOADING (Value = 1): Data is currently being loaded  FileReader.DONE (Vlaue = 2): The entire read request has been completed.
  • 15. File API - Example var file = $("#file")[0].files[0]; var reader = new FileReader(); reader.readAsText (file); reader.onload = function(){ $("#content").val(reader.result); };
  • 16. File API - Blob var file = new Blob( ["這是建立 Blob 的內容!!"], { "type": "text/plain" }); var fileReader = new FileReader(); fileReader.onload = function (event) { console.log('新建 Blob 檔案內容:'+this.result); } ; fileReader.readAsText(file);