{"id":442,"date":"2019-05-18T00:01:54","date_gmt":"2019-05-17T16:01:54","guid":{"rendered":"http:\/\/www.yohz.com\/blogs\/?p=442"},"modified":"2019-09-05T10:24:18","modified_gmt":"2019-09-05T02:24:18","slug":"how-to-merge-multiple-blobs-into-a-single-file","status":"publish","type":"post","link":"https:\/\/www.yohz.com\/blogs\/2019\/05\/18\/how-to-merge-multiple-blobs-into-a-single-file\/","title":{"rendered":"Merge multiple blobs into a single file"},"content":{"rendered":"<p>Some applications break up a file into smaller chunks before storing them into a table.\u00a0 So for e.g. a 200 Kb file might be stored in 4 rows, each storing a maximum of 60 Kb, in the following layout:<\/p>\n<p>ID\u00a0 fileID\u00a0 sequence\u00a0 blobdata<br \/>\n1\u00a0 \u00a0 \u00a0201\u00a0 \u00a0 \u00a0 \u00a01\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 (60 Kb)<br \/>\n2\u00a0 \u00a0 \u00a0201\u00a0 \u00a0 \u00a0 \u00a02\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 (60 Kb)<br \/>\n3\u00a0 \u00a0 \u00a0201\u00a0 \u00a0 \u00a0 \u00a03\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 (60 Kb)<br \/>\n4\u00a0 \u00a0 \u00a0201\u00a0 \u00a0 \u00a0 \u00a04\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 (20 Kb)<\/p>\n<p>When you export the blobs using <a href=\"https:\/\/www.yohz.com\/siv8_details.htm\">SQL Image Viewer<\/a>\/<a href=\"https:\/\/www.yohz.com\/aole_details.htm\">Access OLE Export<\/a>\/<a href=\"https:\/\/www.yohz.com\/sbe_details.htm\">SQL Blob Export<\/a>, 4 files will be created using the default settings.\u00a0 This is because those products treat each row as containing a separate file.<\/p>\n<p style=\"text-align: left;\">To export the 4 rows as a single file, you need to first select the &#8216;<strong>append to file<\/strong>&#8216; option for existing files.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-443 alignnone\" src=\"http:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2019\/05\/append01.png\" alt=\"\" width=\"456\" height=\"41\" srcset=\"https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2019\/05\/append01.png 456w, https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2019\/05\/append01-300x27.png 300w\" sizes=\"(max-width: 456px) 100vw, 456px\" \/><\/p>\n<p>This will cause the blob data to be appended to any existing file of the same name.<\/p>\n<p>Next, you need to ensure that the 4 rows will all export to the same file name.\u00a0 In our example above, we might use the <strong>fileID<\/strong> value as the name of the file, so all 4 rows will export to the same file.<\/p>\n<p>Then, your SQL to export the blobs need to sort the rows so that the blobs get appended to the file in the correct sequence.\u00a0 In our example, this means we need to sort the rows by the <strong>sequence<\/strong> value e.g.<\/p>\n<p style=\"padding-left: 40px;\">SELECT fileID, blobdata FROM mytable ORDER BY sequence<\/p>\n<p>Lastly, we need to ensure that in our output folder, there are no existing files of the same name, otherwise our blobs will get appended to those files.<\/p>\n<p>That&#8217;s basically all you need to do to ensure that the blobs are exported in the correct sequence to a valid file.\u00a0 In summary:<\/p>\n<ul>\n<li>select the <strong>append to file<\/strong> option for existing files<\/li>\n<li>use a naming convention that ensures the related blobs use the same file name<\/li>\n<li>sort the rows in the correct sequence so that the blobs are appended in the correct order<\/li>\n<li>before the export, ensure that no files of the same name are already in the output folder<\/li>\n<\/ul>\n<div class=\"fcbkbttn_buttons_block\" id=\"fcbkbttn_left\"><div class=\"fcbkbttn_like \"><fb:like href=\"https:\/\/www.yohz.com\/blogs\/2019\/05\/18\/how-to-merge-multiple-blobs-into-a-single-file\/\" action=\"like\" colorscheme=\"light\" layout=\"button\"  size=\"small\"><\/fb:like><\/div><div class=\"fb-share-button  \" data-href=\"https:\/\/www.yohz.com\/blogs\/2019\/05\/18\/how-to-merge-multiple-blobs-into-a-single-file\/\" data-type=\"button\" data-size=\"small\"><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Some applications break up a file into smaller chunks before storing them into a table.\u00a0 So for e.g. a 200 Kb file might be stored in 4 rows, each storing a maximum of 60 Kb, in the following layout: ID\u00a0 fileID\u00a0 sequence\u00a0 blobdata 1\u00a0 \u00a0 \u00a0201\u00a0 \u00a0 \u00a0 \u00a01\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[17,44,11],"tags":[18,58,48,12],"_links":{"self":[{"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/posts\/442"}],"collection":[{"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/comments?post=442"}],"version-history":[{"count":4,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/posts\/442\/revisions"}],"predecessor-version":[{"id":512,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/posts\/442\/revisions\/512"}],"wp:attachment":[{"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/media?parent=442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/categories?post=442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/tags?post=442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}