{"id":635,"date":"2018-06-24T00:56:16","date_gmt":"2018-06-23T19:26:16","guid":{"rendered":"http:\/\/www.cyberaka.com\/?p=635"},"modified":"2018-06-24T00:56:16","modified_gmt":"2018-06-23T19:26:16","slug":"triggering-download-of-file-using-javascript","status":"publish","type":"post","link":"https:\/\/www.cyberaka.com\/?p=635","title":{"rendered":"Triggering download of file using JavaScript"},"content":{"rendered":"<p>I recently needed to write a small piece of download code. So you pass in the ID of the document to a REST API and it should give you back a blob of the actual file. The problem however is how to actually save this blob of binary data into a local file. So a quick Googling threw up some interesting links which I finally used to finalize my solution.<\/p>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/40939380\/how-to-get-file-name-from-content-disposition\">Code to detect file name<\/a><\/p>\n<p><a href=\"https:\/\/gist.github.com\/liabru\/11263260\">Code to trigger download<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently needed to write a small piece of download code. So you pass in the ID of the document to a REST API and it should give you back a blob of the actual file. The problem however is how to actually save this blob of binary data into a local file. So a [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[],"class_list":["post-635","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=635"}],"version-history":[{"count":1,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/635\/revisions"}],"predecessor-version":[{"id":636,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/635\/revisions\/636"}],"wp:attachment":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}