<?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 VISHAL SINGH on Medium]]></title>
        <description><![CDATA[Stories by VISHAL SINGH on Medium]]></description>
        <link>https://medium.com/@vishalsingh1812?source=rss-dba7d705060------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by VISHAL SINGH on Medium</title>
            <link>https://medium.com/@vishalsingh1812?source=rss-dba7d705060------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 05:59:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vishalsingh1812/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 upload large files to AWS S3 (latest aws-sdk) using NodeJS?]]></title>
            <link>https://medium.com/@vishalsingh1812/how-to-upload-large-files-to-aws-s3-latest-aws-sdk-using-nodejs-6fc96641248c?source=rss-dba7d705060------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fc96641248c</guid>
            <category><![CDATA[file-size]]></category>
            <category><![CDATA[file-upload]]></category>
            <category><![CDATA[aws-s3]]></category>
            <category><![CDATA[aws-sdk]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[VISHAL SINGH]]></dc:creator>
            <pubDate>Tue, 16 Jan 2024 07:16:57 GMT</pubDate>
            <atom:updated>2024-01-16T07:21:35.627Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*htJ2RyXjToJu7mfm1MY1xQ.jpeg" /></figure><p>uploading small-sized files to AWS s3 is not a big task. but if you are dealing with a huge file size like 2GB then most probably your upload will fail.</p><p>Solution is Multipart!</p><p>So divide the large object into small chunks before uploading it, And keep track of the part too.</p><p>Step: 1</p><pre>npm i aws-sdk</pre><p>Step: 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RG4ON-N8LurRqqslvvVaxw.png" /></figure><p><strong>✅ Done</strong></p><pre>const {S3Client, CreateMultipartUploadCommand, UploadPartCommand, CompleteMultipartUploadCommand} = require(&#39;@aws-sdk/client-s3&#39;);<br> <br>const s3 = new S3Client({<br>    region: &lt;key&gt;,<br>    credentials: {<br>        accessKeyId: &lt;key&gt;,<br>        secretAccessKey: &lt;key&gt;<br>    }<br>});<br><br>const startUpload = async (key) =&gt; {<br>    try {<br>        const params = {<br>            Key: key,<br>            Bucket: &lt;bucket-name&gt;,<br>          };<br>      <br>          const multipart = await s3.send(new CreateMultipartUploadCommand(params));<br>          return multipart.UploadId;<br>    } catch (error) {<br>        console.log(&#39;error startUpload&#39;, error);<br>    }<br>};<br><br>const uploadPart = async (buffer, uploadId, partNumber, key) =&gt; {<br>    try {<br>        const params = {<br>            Key: key,<br>            Bucket: &lt;bucket-name&gt;,<br>            Body: buffer,<br>            PartNumber: partNumber, <br>            UploadId: uploadId, <br>        };<br>        const part = await s3.send(new UploadPartCommand(params));<br>        return Promise.resolve({PartNumber: partNumber, ETag: part.ETag});<br>    } catch (error) {<br>        console.log(&#39;uploadPart&#39;, error);<br>    }  <br>};<br><br>const upload = async (filePath) =&gt; {<br>    const file = fs.readFileSync(filePath); <br>    const key = `event-gallery/${eventName}/${filePath.split(&#39;/&#39;).pop()}`;<br>    const chunkSize = Math.pow(1024, 2) * 10; <br>    const fileSize = file.byteLength;<br>    const iterations = Math.ceil(fileSize / chunkSize); <br>    const arr = Array.from(Array(iterations).keys()); <br>    let uploadId = &#39;&#39;; <br>    try {<br>      uploadId = await startUpload(key);<br>      const parts = await Promise.all(<br>        arr.map(item =&gt; {<br>            return uploadPart(<br>                file.slice(item * chunkSize, (item + 1) * chunkSize),<br>                uploadId,<br>                parseInt(item) + 1,<br>                key<br>            )<br>        })<br>      );<br>      <br>      await s3.send(<br>            new CompleteMultipartUploadCommand({<br>                Bucket: &#39;&lt;bucket-name&gt;&#39;,<br>                Key: key,<br>                UploadId: uploadId,<br>                MultipartUpload: {<br>                    Parts: parts.map(({ ETag }, i) =&gt; ({<br>                    ETag,<br>                    PartNumber: i + 1,<br>                    })),<br>                },<br>            }),<br>      );<br>      <br>      return Promise.resolve({key});<br><br>      } catch(err) {<br>          console.error(err);<br>      }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fc96641248c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Check JWT token are expired]]></title>
            <link>https://medium.com/@vishalsingh1812/check-jwt-token-are-expired-15ab67459c1d?source=rss-dba7d705060------2</link>
            <guid isPermaLink="false">https://medium.com/p/15ab67459c1d</guid>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[validation]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[VISHAL SINGH]]></dc:creator>
            <pubDate>Sat, 16 Dec 2023 06:59:57 GMT</pubDate>
            <atom:updated>2023-12-16T06:59:57.390Z</atom:updated>
            <content:encoded><![CDATA[<pre>function urlBase64Decode(str: string) {<br>  let output = str.replace(/-/g, &#39;+&#39;).replace(/_/g, &#39;/&#39;);<br>  switch (output.length % 4) {<br>    case 0: {<br>      break;<br>    }<br>    case 2: {<br>      output += &#39;==&#39;;<br>      break;<br>    }<br>    case 3: {<br>      output += &#39;=&#39;;<br>      break;<br>    }<br>    default: {<br>      throw new Error(&#39;Illegal base64url string!&#39;);<br>    }<br>  }<br><br>  return b64DecodeUnicode(output);<br>}<br><br>function b64DecodeUnicode(str: any) {<br>  return decodeURIComponent(<br>    Array.prototype.map<br>      .call(<br>        b64decode(str),<br>        (c: any) =&gt; &#39;%&#39; + (&#39;00&#39; + c.charCodeAt(0).toString(16)).slice(-2)<br>      )<br>      .join(&#39;&#39;)<br>  );<br>}<br><br>function b64decode(str: string): string {<br>  const chars =<br>    &#39;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=&#39;;<br>  let output = &#39;&#39;;<br><br>  str = String(str).replace(/=+$/, &#39;&#39;);<br><br>  if (str.length % 4 === 1) {<br>    throw new Error(<br>      &quot;&#39;atob&#39; failed: The string to be decoded is not correctly encoded.&quot;<br>    );<br>  }<br><br>  for (<br>    let bc = 0, bs: any, buffer: any, idx = 0;<br>    (buffer = str.charAt(idx++));<br>    ~buffer &amp;&amp; ((bs = bc % 4 ? bs * 64 + buffer : buffer), bc++ % 4)<br>      ? (output += String.fromCharCode(255 &amp; (bs &gt;&gt; ((-2 * bc) &amp; 6))))<br>      : 0<br>  ) {<br>    buffer = chars.indexOf(buffer);<br>  }<br>  return output;<br>}<br><br>function decodeToken(tokenValue?: string) {<br>  const parts = tokenValue.split(&#39;.&#39;);<br>  if (parts.length !== 3) {<br>    throw new Error(<br>      &quot;The inspected token doesn&#39;t appear to be a JWT. Check to make sure it has three parts and see https://jwt.io for more.&quot;<br>    );<br>  }<br><br>  const decoded = urlBase64Decode(parts[1]);<br>  console.log(&#39;d&#39;, decoded);<br>  if (!decoded) {<br>    throw new Error(&#39;Cannot decode the token.&#39;);<br>  }<br><br>  return JSON.parse(decoded);<br>}<br><br>getTokenExpirationDate(tokenValue: string): Observable&lt;Date | null&gt; {<br>    return of(tokenValue).pipe(<br>      map((token: string) =&gt; {<br>        let decoded: any;<br>        decoded = this.decodeToken(token);<br><br>        if (!decoded.hasOwnProperty(&#39;exp&#39;)) {<br>          return null;<br>        }<br><br>        const date = new Date(0);<br>        date.setUTCSeconds(decoded.exp);<br><br>        return date;<br>      })<br>    );<br>  }<br><br>  isTokenExpired(tokenValue?: string | null, offsetSeconds?: number): Observable&lt;boolean&gt; {<br>    return of(tokenValue ?? &#39;&#39;).pipe(<br>      map((token: string) =&gt; {<br>        if (token === null || token === &#39;&#39;) {<br>          return true;<br>        }<br>        const date = this.getTokenExpirationDate(token);<br>        offsetSeconds = offsetSeconds || 0;<br><br>        if (date === null) {<br>          return true;<br>        }<br>        return !(Number(date.valueOf()) &gt; new Date().valueOf() + offsetSeconds * 1000);<br>      })<br>    );<br>  }<br><br>decodeToken(<br>  &#39;eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjUyNzk1NjY1MTI5NjFjZWE5NTUzYTJmIiwibW9iaWxlX25vIjoiNjMwNjQxNzg4MCIsInVzZXJfdHlwZSI6IlVTRVIiLCJ0b2tlblR5cGUiOiJhdXRoIiwiaWF0IjoxNzAyNzA3MDMxLCJleHAiOjE3MDI3OTM0MzF9.qhhhNhZe6R18GnCxdesjutB5wB2JBffOP9_tzkeflLQ&#39;<br>);</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15ab67459c1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Auto-focus a form control with an Angular directive]]></title>
            <link>https://medium.com/@vishalsingh1812/auto-focus-a-form-control-with-an-angular-directive-8de5cd95a34e?source=rss-dba7d705060------2</link>
            <guid isPermaLink="false">https://medium.com/p/8de5cd95a34e</guid>
            <category><![CDATA[queryselector]]></category>
            <category><![CDATA[angular-forms]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[custom-directive]]></category>
            <category><![CDATA[custome-form-directive]]></category>
            <dc:creator><![CDATA[VISHAL SINGH]]></dc:creator>
            <pubDate>Mon, 09 May 2022 17:59:20 GMT</pubDate>
            <atom:updated>2022-05-09T17:59:20.741Z</atom:updated>
            <content:encoded><![CDATA[<p>In an application that has a lot of CRUD forms, it can be useful for users to give focus to a form control. It’s a small thing that can improve the user experience by a lot. For example, when a modal opens and the user has to move the mouse towards the form control and click it, instead, the user can just start to type when the model is opened.</p><p>While it’s possible to focus an element with the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete">autocomplete</a> attribute, I found that creating an <a href="https://angular.io/guide/attribute-directives">Angular Directive</a> is more convenient.</p><p>When the directive’s <strong>selector</strong> is set to <strong>form</strong>, every form in the application will automatically focus the first form control. The directive below also gives focus to the form control that&#39;s invalid when the form is submitted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z6DNojARrFBfNt6Njsiy0Q.png" /><figcaption><a href="https://github.com/newvishal/custome-directive/blob/master/src/app/form-focus.directive.ts">https://github.com/newvishal/custome-directive/blob/master/src/app/form-focus.directive.ts</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8de5cd95a34e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multi-Language Support in Angular]]></title>
            <link>https://medium.com/@vishalsingh1812/multi-language-support-in-angular-90a69fe46138?source=rss-dba7d705060------2</link>
            <guid isPermaLink="false">https://medium.com/p/90a69fe46138</guid>
            <category><![CDATA[transloco]]></category>
            <category><![CDATA[locality]]></category>
            <category><![CDATA[multilanguage]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[howtoaddtransloco]]></category>
            <dc:creator><![CDATA[VISHAL SINGH]]></dc:creator>
            <pubDate>Fri, 06 May 2022 17:07:09 GMT</pubDate>
            <atom:updated>2022-05-06T17:07:09.601Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*0WfidOXy3HRWLnjYiriMXg.jpeg" /><figcaption>Add New Feature</figcaption></figure><p>Recently I have added a <strong>multi-language support</strong> feature for my application to intract with local people. these are the steps 😵</p><p><strong>Step 1: </strong>Install npm dependence<strong> “@ngneat/transloco”: “2.19.3”</strong></p><p><strong>Step 2: </strong>Create new file<strong> http-loader.ts </strong>and write this code<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z0jFYUilCVBjtqnCVVAEXw.png" /></figure><p><strong>Step 3: </strong>Make a new folder<strong> i18n </strong>in<strong> assets </strong>and add<strong> json file </strong>of languages like this 👇.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*QYqAS-TU6e4ZIC4UKWb4uQ.png" /></figure><p><strong>Step 4: </strong>Add your<strong> key — value </strong>pair here. keys of all files must be the same. and here you can add a variable in <strong>“{{value}}” . </strong>the values of these variables can be set<strong> </strong>dynamically<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ar5gOF1OFJubvwO20aJqQ.png" /></figure><p><strong>Step 5:</strong> Import <strong>TranslocoModule </strong>in<strong> app.module.ts. </strong>and also set providers, which is basically the configuration of Transloco like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AOXmkbQF-e4PTShfQfIahg.png" /></figure><p><strong>Step 6: </strong><em>And And And Don’t forget to import</em><strong><em> HttpClientModule </em></strong><em>otherwise you got errors…………………….</em></p><p><strong>Step 7:</strong> And the final one is …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8EN7syfvoZ5Mhu7w-uJFvQ.png" /></figure><p>And — — — — — — — — — — — -<strong>Done — — — — — — — — — — — — — — — —</strong></p><p>for more details visit <a href="https://ngneat.github.io/transloco/">https://ngneat.github.io/transloco/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90a69fe46138" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>