<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Adenitire Ayomikun on Medium]]></title>
        <description><![CDATA[Stories by Adenitire Ayomikun on Medium]]></description>
        <link>https://medium.com/@adenitireayomikun?source=rss-9a8022eb41fa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*O3NAOTbLBejwfUOI.</url>
            <title>Stories by Adenitire Ayomikun on Medium</title>
            <link>https://medium.com/@adenitireayomikun?source=rss-9a8022eb41fa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 19:04:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adenitireayomikun/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to unzip an uploaded zip folder in Vue js using JSZip]]></title>
            <link>https://medium.com/@adenitireayomikun/how-to-unzip-an-uploaded-zip-folder-in-vue-js-using-jszip-bd727f25612b?source=rss-9a8022eb41fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd727f25612b</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[saas]]></category>
            <dc:creator><![CDATA[Adenitire Ayomikun]]></dc:creator>
            <pubDate>Wed, 22 Jun 2022 22:02:40 GMT</pubDate>
            <atom:updated>2022-06-22T22:02:40.584Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*DBNbUFmrjahMouq9Q49y5Q.jpeg" /></figure><p>The software development market is very diverse and the range of tasks could vary a lot. As developers, one will be required to accept data of different formats from users ranging from images, and videos, hence some data might be required to be uploaded in zip format in order to ease the user stress.</p><p>In this tutorial, I will be teaching you how to accept an uploaded zip file in Vue js and run some validation on it. However, I will be using a zip file that contains images and validate it based on the following criteria</p><ol><li>The number of images inside the zip folder must not exceed 400 images.</li><li>Images inside the zip must be of height: 400 and width: 400.</li></ol><p><strong>Installation</strong></p><p>First, we will need to install Node on your machine. <a href="https://nodejs.org/en/download/">Here</a> you can download and install it.</p><p>Next, we will need to install the Vue CLI library and create a Vue app and install <a href="https://stuk.github.io/jszip/">Jszip</a> library:</p><pre>npm install -g @vue/cli</pre><pre>vue create hello-world</pre><pre>npm install jszip</pre><p>Create your component with any name of your choice but in this tutorial, I will name it ZipFileComponent.vue and paste the below code inside it</p><pre>&lt;template&gt;<br>   &lt;form <em>v-on:submit.prevent</em>=&quot;uploadFiles&quot;&gt;<br>      &lt;input <em>type</em>=&quot;file&quot; <em>name</em>=&quot;zip_file&quot; <em>accept</em>=&quot;.zip&quot;&gt;&lt;/input&gt;<br>      &lt;button <em>type</em>=&quot;submit&quot;&gt;Upload file&lt;/button&gt;<br>   &lt;/form&gt;<br>&lt;/template&gt;</pre><p>import jszip library into the component using</p><pre><em>import </em>* <em>as JSZip from </em>&#39;jszip&#39;</pre><p>In the methods section inside your component paste the code below</p><pre><em>async </em>uploadFiles(event){<br>   <em>let </em>fileUpload = event.target.files[0]<br>   <em>let </em>results = <em>this</em>.unzipFile(fileUpload)<br>   <em>if </em>(results[&#39;status&#39;] === <em>true</em>) {<br>      <em>if </em>(results[&#39;total_images&#39;] &lt;= 0) {<br>         <em>// return an error to the user informing the user that the zip folder is empty<br>      </em>}<br>      <em>if </em>(results[&#39;total_images&#39;].length &gt; 400) {<br>         <em>// return an error to the user informing the user -&gt; images inside the zip folder exceeded expected images<br>      </em>}<br>      <em>if </em>(results[&#39;image_with_error&#39;].length &gt; 0){<br>         <em>// if an of the images fail when validating their height and width<br>         // return an error to the user with name of the images that fail during validation<br>      </em>}<br><br>   } <em>else </em>{<br>      <em>// if uploaded zip folder is either corrupt<br>   </em>}<br>}</pre><p>Then paste the method that handles the actual folder unzip</p><pre><em>async </em>unzipFile(data) {<br>   <em>try </em>{<br>      <em>let </em>context = {&#39;status&#39;: <em>true</em>}<br>      <em>const </em>zipper = <em>new </em>JSZip()<br>      <em>const </em>zip = await zipper.loadAsync(data)<br>      context[&#39;total_images&#39;] = Object.keys(zip.files).length - 1<br>      <em>let </em>imageWithError = []<br>      <em>let </em>allImages = []<br>      <em>for </em>(<em>const </em>[key, value] <em>of </em>Object.entries(zip.files)) {<br>         await zip.files[key].async(&#39;base64&#39;).then(<em>function </em>(fileData) {<br>            <em>if </em>(fileData !== &#39;&#39;) {<br>               <em>const </em>image = <em>new Image</em>();<br>               image.src = `data:image/png;base64,${fileData}`;<br>               image.onload = <em>function </em>() {<br>                  allImages.push(key.split(&#39;/&#39;)[1])<br>                  <em>if </em>(image.width !== 400 &amp;&amp; image.height !== 400) {<br>                     imageWithError.push(key.split(&#39;/&#39;)[1])<br>                  }<br>               };<br>            }<br>         })<br>      }<br>      context[&#39;image_with_error&#39;] = imageWithError<br>      context[&#39;all_images&#39;] = allImages<em><br>      </em>context[&#39;files&#39;] = zip.files<br>      <em>return </em>context<br>   } <em>catch </em>(e) {<br>      <em>return </em>{&#39;status&#39;: <em>false</em>, &#39;message&#39;: e}<br>   }<br><br>},</pre><p>The <strong>unzipFile</strong> method above takes the raw zip file that is being uploaded by the user and processes it based on the following steps:</p><ol><li>Unzip the folder using <strong>jszip </strong>library</li><li>Get the total images inside the zip folder by subtracting 1 from the total number of files returned by the <strong>jszip </strong>due to an empty file that is added automatically by the library.</li><li>Run images validation using for loop by converting it from base64 to the actual image thereby extracting the image height and width</li><li>The function returns an Object containing the status of the process which could be either True or False.</li><li>Viola, you now have access to all parameters you can use for validation.</li></ol><p>If you’re interested in continuing to explore <strong>VueJS </strong>and<strong> JSZip</strong>, check out:</p><ul><li><a href="https://vuejs.org/v2/guide/">The Official VueJS Docs</a> 🎊 🎊</li><li><a href="https://github.com/vuejs/awesome-vue">Awesome Vue</a></li><li><a href="https://stuk.github.io/jszip/">https://stuk.github.io/jszip/</a></li></ul><p>If you like this post a clap will be so much appreciated.</p><p>Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd727f25612b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>