{"id":1112,"date":"2022-01-02T07:13:00","date_gmt":"2022-01-01T22:13:00","guid":{"rendered":"http:\/\/kiyonagi.jp\/?p=1112"},"modified":"2022-01-05T06:40:55","modified_gmt":"2022-01-04T21:40:55","slug":"flask%e3%80%81send_file%e3%81%a7%e3%83%90%e3%82%a4%e3%83%8a%e3%83%aa%e3%82%92dl%e3%81%95%e3%81%9b%e3%82%8b%e5%ae%9f%e8%a3%85","status":"publish","type":"post","link":"http:\/\/kiyonagi.jp\/?p=1112","title":{"rendered":"flask\u3001send_file\u3067\u30d0\u30a4\u30ca\u30ea\u3092DL\u3055\u305b\u308b\u5b9f\u88c5"},"content":{"rendered":"\n<p>2\u6642\u9593\u304f\u3089\u3044\u30cf\u30de\u3063\u305f\u306e\u3067\u30e1\u30e2\u3057\u3066\u304a\u304f\u3002<br><br>Excel\u306e\u5834\u5408<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$.ajax({\n    type: \"GET\",\n    url: \"\/downloadExcelReport\/\" + customerId + \"\/\" + deliverYmd.split(\"\/\").join(\"-\") + \"\",\n    xhrFields    : {responseType : 'blob'},\n  }).done(function(data, textStatus, jqXHR ) {\n    var blob=new Blob(&#91;data], \n        {type: \"application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64\"});\n    var link = document.createElement('a');\n    link.href = window.URL.createObjectURL(blob);\n    link.download = \"\" + Math.random().toString(32).substring(2) + \".xlsx\";\n    link.click();\n  }).fail(function(data) {\n    alert(\"\u30a8\u30e9\u30fc\uff1a\" + data.statusText);\n  }).always(function(data) {\n    ;\n});<\/code><\/pre>\n\n\n\n<p>ajax\u306e\u30aa\u30d7\u30b7\u30e7\u30f3 xhrFields    : {responseType : &#8216;blob&#8217;} \u304c\u308f\u304b\u3089\u306a\u304f\u3066\u3002<br>\u4eca\u3082\u6b63\u76f4\u308f\u304b\u3063\u3066\u306a\u3044\u3002\u3069\u3046\u3057\u3066get\u30ea\u30af\u30a8\u30b9\u30c8\u3059\u308b\u6bb5\u968e\u3067\u3001xhr\uff08XMLHttpRequest\uff09\u3067\u3042\u308b\u3053\u3068\u3092\u4f1d\u3048\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u304b\u3002\u3053\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u306a\u304f\u3066\u3082\u30b5\u30fc\u30d0\u5074\u3067\u306f\u6b63\u5e38\u306axlsx\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u3066\u3044\u308b\u3002\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3068\u304d\u306b\u306f\u30a8\u30af\u30bb\u30eb\u3060\u308d\u3046\u3068\u305d\u306e\u4ed6\u306e\u30d0\u30a4\u30ca\u30ea\u30d5\u30a1\u30a4\u30eb\u3060\u308d\u3046\u3068\u540c\u3058\u6271\u3044\u3060\u3068\u601d\u3046\u3093\u3060\u3051\u3069\u3002\u3072\u3068\u307e\u305a\u3053\u308c\u3067\u5b9f\u88c5\u306f\u3067\u304d\u305f\u3093\u3060\u304c\u8151\u306b\u843d\u3061\u306a\u3044\u3002<br><br>PDF\u306e\u5834\u5408<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/1000\u4eba\u5206\u306ePDF\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u4f1d\u3048\u3066\u3001\u30de\u30fc\u30b8PDF\u3092\u3082\u3089\u3046\n$.ajax({\n    type: \"POST\",\n    data: JSON.stringify({\"data\":files}),\n    url: \"\/pdfMergeSeikyusho\",\n    contentType:'application\/json'\n}).done(function(data) {\n    var blob=new Blob(&#91;data], {type: \"application\/pdf\"});\n    var link = document.createElement('a');\n    link.href = window.URL.createObjectURL(blob);\n    link.download = \"\" + Math.random().toString(32).substring(2) + \".pdf\";\n    link.click();\n}).fail(function(data) {\n    alert(\"\u30a8\u30e9\u30fc\uff1a\" + data.statusText);\n}).always(function(data) {\n    ;\n});<\/code><\/pre>\n\n\n\n<p>\u3053\u308c\u306fPDF\u7528\u306e\u30d6\u30ed\u30c3\u30af\u3002\u3060\u3044\u3076\u524d\u306b\u5b9f\u88c5\u3057\u305f\u30b3\u30fc\u30c9\u3067\u3001\u3053\u3063\u3061\u306f\u6a19\u6e96\u7684\u306a\u30aa\u30d7\u30b7\u30e7\u30f3\u3067contentType: application\/json \u3068\u3057\u3066\u3044\u308b\u3002\u4e00\u65b9\u3067\u30b5\u30fc\u30d0\u304b\u3089\u53d7\u3051\u53d6\u308b\u3068\u304d\u306eBlob\u5909\u63db\u3067 &#8220;application\/pdf&#8221;\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u3002pdf\u306f\u3053\u308c\u3067OK\u3002<br><br>\u3061\u306a\u307f\u306b\u3001csv\u306e\u5834\u5408<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$.ajax({\n    type: \"GET\",\n    url: \"\/getCsvData\/\" + viewnm + \"\/\"  + nentuki + \"\/\" + groupkb + \"\/\" + tanto + \"\"\n}).done(function(data) {\n    let bom  = new Uint8Array(&#91;0xEF, 0xBB, 0xBF]);\n    var blob=new Blob(&#91;bom, data], {type: \"text\/csv\"});\/\/\n    var link = document.createElement('a');\n    link.href = window.URL.createObjectURL(blob);\n    link.download = \"\" + Math.random().toString(32).substring(2) + \".csv\";\n    link.click();\n}).fail(function(data) {\n    alert(\"\u30a8\u30e9\u30fc\uff1a\" + data.statusText);\n}).always(function(data) {\n    ;\n});<\/code><\/pre>\n\n\n\n<p>unicode\u306e\u305f\u3081js\u5074\u3067bom\u4ed8\u304dblob\u5909\u63db\u3002\u3053\u308c\u3067csv\u306e\u6587\u5b57\u5316\u3051\u3092\u9632\u3050\u3002\u3053\u306e\u985e\u306f\u4ed5\u4e8b\u3067\u3082\u6563\u3005\u7d4c\u9a13\u6e08\u307f\u3002<br><br>\u53d7\u3051\u53d6\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u7a2e\u985e\u3054\u3068\u306bcontent-type\u3092\u610f\u8b58\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u306f\u3001http\u30d8\u30c3\u30c0\u30fc\u304c\u7570\u306a\u308b\u304b\u3089\u3068\u3044\u3046\u306e\u306f\u308f\u304b\u308b\u3051\u3069\u3001ajax\u30aa\u30d7\u30b7\u30e7\u30f3\uff08\u30ea\u30af\u30a8\u30b9\u30c8\u30d5\u30a7\u30fc\u30ba\uff09\u3067\u305d\u308c\u304c\u5fc5\u8981\u306a\u306e\u306f\u3069\u3046\u3057\u3066\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2\u6642\u9593\u304f\u3089\u3044\u30cf\u30de\u3063\u305f\u306e\u3067\u30e1\u30e2\u3057\u3066\u304a\u304f\u3002 Excel\u306e\u5834\u5408 ajax\u306e\u30aa\u30d7\u30b7\u30e7\u30f3 xhrFields : {responseType : &#8216;blob&#8217;} \u304c\u308f\u304b\u3089\u306a\u304f\u3066\u3002\u4eca\u3082\u6b63\u76f4\u308f\u304b\u3063\u3066\u306a\u3044\u3002\u3069\u3046\u3057&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11,4],"tags":[],"class_list":["post-1112","post","type-post","status-publish","format-standard","hentry","category-tech","category-4"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/kiyonagi.jp\/index.php?rest_route=\/wp\/v2\/posts\/1112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/kiyonagi.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kiyonagi.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kiyonagi.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/kiyonagi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1112"}],"version-history":[{"count":3,"href":"http:\/\/kiyonagi.jp\/index.php?rest_route=\/wp\/v2\/posts\/1112\/revisions"}],"predecessor-version":[{"id":1117,"href":"http:\/\/kiyonagi.jp\/index.php?rest_route=\/wp\/v2\/posts\/1112\/revisions\/1117"}],"wp:attachment":[{"href":"http:\/\/kiyonagi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kiyonagi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1112"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kiyonagi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}