Make your own Storage Engine for Multer in TypeScript

Make your own Storage Engine for Multer in TypeScript

Make your own Storage Engine for Multer in TypeScript. Before jumping right into making your own storage engine, let's discuss my own need it in the first place and some of its applications. We have a fair idea about multer, get discuss the need for a custom storage engine and make one using TypeScript.

Before jumping right into making your own storage engine, let's discuss why we need it in the first place and some of its applications.

Here’s the link to the GitHub repo for the following tutorial.

At this point, I assume that you have a clear idea of what multer is and what it is used for. Just to be on the same page here is a quick introduction to multer in its “out-of-the-box” form:-

So basically multer is used to parse data from HTTP requests with

Content-Type header set to multipart/formdata . Content-Type header in an HTTP request describes the types of resources shared over the network. And these resources need special middlewares to be parsed and made available in the server-side application. Content-Type header of application/json, application/x-form-www-urlencoded, text/html can be parsed via  body-parser but multipart/formdataneeds a different middleware i.e. multer. mutipart/formdata Content-Type means that apart from JSON or plain text data, resources may have Blob or File type fields as well. Without these middlewares, we won’t be able to use the resources sent over by the user. The req.body we use so casually in an express app, would have always returned an empty object if it wasn’t for these middlewares.

Now that we have a fair idea about multer, let's discuss the need for a custom storage engine and make one using TypeScript.

Storage Engines in Multer.

Storage engines are basically classes that deal with the file once they are parsed this includes storing, deleting, and modifying the original file. By default, multer comes with 2 storage engines, DiskStorage, and MemoryStorage. DiskStorage stores the file on disk at a given location whereas MemoryStorage stores the file’s content as a buffer in the application’s memory.

typescript javascript coding web-development

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Hire Dedicated JavaScript Developers -Hire JavaScript Developers

Hire dedicated JavaScript Developers who are proficient in AngularJS, ReactJS, NodeJS, & VueJS frameworks. Get flexible hiring models as per your business requirements.

TypeScript Tutorial For JavaScript Developers - TypeScript Basics

TypeScript Tutorial For JavaScript Developers - TypeScript Basics. I will show you guys 4 example of JavaScript code, and how to convert it to TypeScript. This is a typescript beginners tutorial.

Exposing Most Common Web Development Myths | ByteCipher

Are you looking for the best Web and Mobile App Development Company in India? We at ByteCipher are offering creative & custom web and mobile app development services worldwide

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

Important Reasons to Hire a Professional Web Development Company

    You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...