<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gervais Ishimwe</title>
    <description>The latest articles on DEV Community by Gervais Ishimwe (@ishgervais).</description>
    <link>https://dev.to/ishgervais</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F548828%2F8fadbb19-5fa9-41d5-aa32-bf6cbb0d1ab2.jpeg</url>
      <title>DEV Community: Gervais Ishimwe</title>
      <link>https://dev.to/ishgervais</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ishgervais"/>
    <language>en</language>
    <item>
      <title>FileUpload in node-ts using formidable module
</title>
      <dc:creator>Gervais Ishimwe</dc:creator>
      <pubDate>Wed, 21 Apr 2021 12:28:37 +0000</pubDate>
      <link>https://dev.to/ishgervais/fileupload-in-node-ts-using-formidable-module-nao</link>
      <guid>https://dev.to/ishgervais/fileupload-in-node-ts-using-formidable-module-nao</guid>
      <description>&lt;p&gt;class FileUploader {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FileUploader() {}

async uploadFile(req: Request, res: Response) {
    let data: any = {
        files: []
    }

    let form: any = new Formidable.IncomingForm({
        multiples: true,
        keepExtensions: true,
        uploadDir: uploadDir
    })

    form.on("fileBegin", (name: string, file: any) =&amp;gt; {
        const [fileName, fileExt] = file.name.split(".");
        const newFileName = `${fileName}_${new Date().getTime()}.${fileExt}`;
        data.files.push(newFileName);
        file.path = path.join(uploadDir, newFileName);
    })


    form.parse(req, async (err, fields, files) =&amp;gt; {
        try {

            //get other fields
            data = {
                ...data,
                ...fields
            };
            if (err) return res.status(500).json({
                error: err
            });
            return res.status(200).json({
                success: true,
                data
            })

        } catch (error) {
            res.json({
                success: false,
                error: "Error occured"
            })
        }
    });

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Gf2KqufQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3w25rzarfu3ub96nw590.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Gf2KqufQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3w25rzarfu3ub96nw590.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
