{"id":634,"date":"2012-11-12T23:52:56","date_gmt":"2012-11-12T14:52:56","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=634"},"modified":"2018-11-14T16:33:59","modified_gmt":"2018-11-14T07:33:59","slug":"html5-%e3%81%ae-file-api-%e3%81%a7%e3%83%89%e3%83%a9%e3%83%83%e3%82%b0%ef%bc%86%e3%83%89%e3%83%ad%e3%83%83%e3%83%97%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2012\/11\/12\/html5-%e3%81%ae-file-api-%e3%81%a7%e3%83%89%e3%83%a9%e3%83%83%e3%82%b0%ef%bc%86%e3%83%89%e3%83%ad%e3%83%83%e3%83%97%e3%81%99%e3%82%8b\/","title":{"rendered":"HTML5 \u306e File API \u3067\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u3059\u308b"},"content":{"rendered":"<p>\u3053\u3093\u3061\u306b\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n<p>HTML5 \u306b\u306f File API \u3068\u3044\u3046\u3082\u306e\u304c\u3042\u307e\u3059\u3002<\/p>\n<p>File API \u3092\u4f7f\u3046\u3068\u30ed\u30fc\u30ab\u30eb PC \u304b\u3089\u30d6\u30e9\u30a6\u30b6\u306b\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f File API \u306b\u3088\u308b\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u51e6\u7406\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u4ee5\u4e0b\u306e HTML \u304b\u3089\u59cb\u3081\u307e\u3057\u3087\u3046\uff01<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;title&gt;HTML5 \u3067\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7&lt;\/title&gt;\r\n    &lt;script src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.7.2\/jquery.min.js\"&gt;&lt;\/script&gt;\r\n    &lt;script&gt;\r\n      $(function() {\r\n        \/\/ TODO \u3053\u3053\u306b\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u306b\u5fc5\u8981\u306a\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u307e\u3059.\r\n      });\r\n    &lt;\/script&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt; \r\n    &lt;div id=\"droppable\" style=\"border: gray solid 1em; padding: 2em;\"&gt;\r\n      \u30d5\u30a1\u30a4\u30eb\u3092\u30c9\u30ed\u30c3\u30d7\u3057\u3066\u304f\u3060\u3055\u3044\u3002\r\n    &lt;\/div&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3053\u3053\u3067\u4e0b\u6e96\u5099\u3068\u524d\u63d0\u6761\u4ef6\u3092\u660e\u793a\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u30d6\u30e9\u30a6\u30b6\u4f9d\u5b58\u306e\u30b3\u30fc\u30c9\u3067\u672c\u8cea\u7684\u306a\u51e6\u7406\u3092\u57cb\u3082\u308c\u3055\u305b\u306a\u3044\u305f\u3081\u306b\u3001jQuery \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/li>\n<li>\u30c9\u30ed\u30c3\u30d7\u3057\u305f\u3044\u9818\u57df ( &lt;div&gt; ) \u306b droppable \u3068\u3044\u3046 id \u3092\u4ed8\u3051\u3001\u898b\u3084\u3059\u3044\u3088\u3046\u306b\u30b9\u30bf\u30a4\u30eb\u3092\u6307\u5b9a\u3057\u307e\u3057\u305f\u3002<\/li>\n<li>\u3053\u308c\u304b\u3089\u300cTODO \u3053\u3053\u306b\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u306b\u5fc5\u8981\u306a\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u307e\u3059.\u300d\u3068\u3044\u3046\u30b3\u30e1\u30f3\u30c8\u306e\u90e8\u5206\u3092\u57cb\u3081\u3066\u3044\u304d\u307e\u3059\u3002<\/li>\n<\/ul>\n<p>\u4eca\u306e\u6bb5\u968e\u3067\u30d6\u30e9\u30a6\u30b6\u3067\u8868\u793a\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<div id=\"attachment_637\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2012\/11\/1.png\" rel=\"facebox\" rel=\"attachment wp-att-637\"><img aria-describedby=\"caption-attachment-637\" loading=\"lazy\" class=\"size-medium wp-image-637\" title=\"\u30c9\u30ed\u30c3\u30d7\u306e\u305f\u3081\u306e\u3001\u305d\u306e\uff11\" src=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2012\/11\/1-300x184.png\" alt=\"\" width=\"300\" height=\"184\" srcset=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2012\/11\/1-300x184.png 300w, https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2012\/11\/1.png 732w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-637\" class=\"wp-caption-text\">\u30c9\u30ed\u30c3\u30d7\u306e\u305f\u3081\u306e\u3001\u305d\u306e\uff11<\/p><\/div>\n<p>\u305d\u308c\u3067\u306f\u3001\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u306e\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<p>\u7d30\u5207\u308c\u306e\u30b3\u30fc\u30c9\u3092\u51fa\u3057\u3066\u3082\u5206\u304b\u308a\u3065\u3089\u3044\u306e\u3067\u3001\u4e00\u6c17\u306b\u5b8c\u6210\u5f62\u306e\u30b3\u30fc\u30c9\u3092\u51fa\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;title&gt;HTML5 \u3067\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7&lt;\/title&gt;\r\n    &lt;script src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.7.2\/jquery.min.js\"&gt;&lt;\/script&gt;\r\n    &lt;script language=\"javascript\"&gt;\r\n      $(function() {\r\n        var droppable = $(\"#droppable\");\r\n\r\n        \/\/ File API \u304c\u4f7f\u7528\u3067\u304d\u306a\u3044\u5834\u5408\u306f\u8ae6\u3081\u307e\u3059.\r\n        if(!window.FileReader) {\r\n          alert(\"File API \u304c\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\");\r\n          return false;\r\n        }\r\n\r\n        \/\/ \u30a4\u30d9\u30f3\u30c8\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3059\u308b\u30cf\u30f3\u30c9\u30e9\u3067\u3059.\r\n        var cancelEvent = function(event) {\r\n            event.preventDefault();\r\n            event.stopPropagation();\r\n            return false;\r\n        }\r\n\r\n        \/\/ dragenter, dragover \u30a4\u30d9\u30f3\u30c8\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u51e6\u7406\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u307e\u3059.\r\n        droppable.bind(\"dragenter\", cancelEvent);\r\n        droppable.bind(\"dragover\", cancelEvent);\r\n\r\n        \/\/ \u30c9\u30ed\u30c3\u30d7\u6642\u306e\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u8a2d\u5b9a\u3057\u307e\u3059.\r\n        var handleDroppedFile = function(event) {\r\n          \/\/ \u30d5\u30a1\u30a4\u30eb\u306f\u8907\u6570\u30c9\u30ed\u30c3\u30d7\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u304c, \u3053\u3053\u3067\u306f 1 \u3064\u76ee\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3044\u307e\u3059.\r\n          var file = event.originalEvent.dataTransfer.files[0];\r\n\r\n          \/\/ \u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u306f FileReader \u3067\u8aad\u307f\u8fbc\u307f\u307e\u3059.\r\n          var fileReader = new FileReader();\r\n          fileReader.onload = function(event) {\r\n            \/\/ event.target.result \u306b\u8aad\u307f\u8fbc\u3093\u3060\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u304c\u5165\u3063\u3066\u3044\u307e\u3059.\r\n            \/\/ \u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u3067\u30d5\u30a1\u30a4\u30eb\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u5834\u5408\u306f result \u306e\u5185\u5bb9\u3092 Ajax \u3067\u30b5\u30fc\u30d0\u306b\u9001\u4fe1\u3057\u307e\u3057\u3087\u3046!\r\n            $(\"#droppable\").text(\"[\" + file.name + \"]\" + event.target.result);\r\n          }\r\n          fileReader.readAsText(file);\r\n\r\n          \/\/ \u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u51e6\u7406\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u307e\u3059.\r\n          cancelEvent(event);\r\n          return false;\r\n        }\r\n\r\n        \/\/ \u30c9\u30ed\u30c3\u30d7\u6642\u306e\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u8a2d\u5b9a\u3057\u307e\u3059.\r\n        droppable.bind(\"drop\", handleDroppedFile);\r\n      });\r\n    &lt;\/script&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;div id=\"droppable\" style=\"border: gray solid 1em; padding: 2em;\"&gt;\r\n      \u30d5\u30a1\u30a4\u30eb\u3092\u30c9\u30ed\u30c3\u30d7\u3057\u3066\u304f\u3060\u3055\u3044\u3002\r\n    &lt;\/div&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u91cd\u8981\u306a\u90e8\u5206\u306f\u30b3\u30fc\u30c9\u4e2d\u306e\u30b3\u30e1\u30f3\u30c8\u3067\u88dc\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u30dd\u30a4\u30f3\u30c8\u306f\u3001<\/p>\n<ul>\n<li>dragenter \u3068 dragover \u30a4\u30d9\u30f3\u30c8\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u51e6\u7406\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3059\u308b\u3002<\/li>\n<li>drop \u30a4\u30d9\u30f3\u30c8\u3067\u30c9\u30ed\u30c3\u30d7\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb\u306e\u51e6\u7406\u3092\u884c\u3046\u3002<\/li>\n<li>\u30c9\u30ed\u30c3\u30d7\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u306f FileReader \u3067\u8aad\u307f\u8fbc\u3080\u3002<\/li>\n<\/ul>\n<p>\u3068\u3044\u3063\u305f\u3068\u3053\u308d\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u5fc5\u8981\u6700\u4f4e\u9650\u306e\u51e6\u7406\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u5b9f\u969b\u306b\u52d5\u304b\u3057\u3066\u3044\u308b\u3068\u3001<\/p>\n<ul>\n<li>\u60f3\u5b9a\u5916\u306e\u9818\u57df\u306b\u30c9\u30ed\u30c3\u30d7\u3055\u308c\u3066\u30d6\u30e9\u30a6\u30b6\u3067\u666e\u901a\u306b\u30d5\u30a1\u30a4\u30eb\u304c\u958b\u304b\u308c\u3066\u3057\u307e\u3063\u305f\u3002\u2192\u30c9\u30ed\u30c3\u30d7\u53ef\u80fd\u306a\u9818\u57df\u306f\u5e83\u304f\u3057\u305f\u65b9\u304c\u826f\u3055\u305d\u3046\u3002<\/li>\n<li>\u30d5\u30a1\u30a4\u30eb\u3067\u306f\u306a\u304f\u30d5\u30a9\u30eb\u30c0\u304c\u30c9\u30ed\u30c3\u30d7\u3055\u308c\u305f\u3002\u2192\u30fb\u30fb\u30fb\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3067\u304d\u306a\u3044\u3063\u3059\uff08\uff3e\uff3e\uff1b<\/li>\n<li>\u753b\u50cf\u306a\u3069\u306e\u30d0\u30a4\u30ca\u30ea\u30d5\u30a1\u30a4\u30eb\u3082\u30c9\u30ed\u30c3\u30d7\u3055\u308c\u308b\u3002\u2192\u52dd\u624b\u306b\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3057\u304b\u30c9\u30ed\u30c3\u30d7\u3055\u308c\u306a\u3044\u3068\u601d\u3044\u8fbc\u3093\u3067\u307e\u3057\u305f\uff08\uff3e\uff3e\uff1b\uff1b<\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u3053\u3068\u306b\u6c17\u4ed8\u3044\u305f\u308a\u3057\u307e\u3059\u306e\u3067\u3001\u3054\u7528\u5fc3\u3092\u3002\u3002\uff08\uff3e\uff3e\uff1b\uff1b\uff1b<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u3061\u306b\u306f\u3001\u9234\u6728\u3067\u3059\u3002<br \/>\nHTML5 \u306b\u306f File API \u3068\u3044\u3046\u3082\u306e\u304c\u3042\u307e\u3059\u3002<br \/>\nFile API \u3092\u4f7f\u3046\u3068\u30ed\u30fc\u30ab\u30eb PC \u304b\u3089\u30d6\u30e9\u30a6\u30b6\u306b\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/><a href=\"https:\/\/www.techscore.com\/blog\/2012\/11\/12\/html5-%e3%81%ae-file-api-%e3%81%a7%e3%83%89%e3%83%a9%e3%83%83%e3%82%b0%ef%bc%86%e3%83%89%e3%83%ad%e3%83%83%e3%83%97%e3%81%99%e3%82%8b\/\">\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[20,53,52],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/634"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=634"}],"version-history":[{"count":1,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/634\/revisions"}],"predecessor-version":[{"id":6835,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/634\/revisions\/6835"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}