Restrictions on File Size in Express Server (Exceeding 50MB)

Is there a method to upload files larger than 50 mb on the express server? I keep encountering the file size limitation of 50 mb.

Appreciate any help. Thank you.

Answer №1

For uploading files of larger size, I implemented the use of multer along with GridFsStorage and streams.

const multer = require("multer");
const { GridFsStorage } = require("multer-gridfs-storage");
const Grid = require("gridfs-stream");

const conn = mongoose.createConnection(mongoURI);

// Initializing gfs
let gfs;

conn.once("open", () => {
  // Initialize stream
  gfs = Grid(conn.db, mongoose.mongo);
  gfs.collection("uploads");
});

// Setting up storage engine
const storage = new GridFsStorage({
  url: mongoURI,
  file: (req, file) => {
    return new Promise((resolve, reject) => {
      crypto.randomBytes(16, (err, buf) => {
        if (err) {
          return reject(err);
        }
        const filename = buf.toString("hex") + path.extname(file.originalname);
        const fileInfo = {
          filename: filename,
          bucketName: "uploads",
        };
        resolve(fileInfo);
      });
    });
  },
});
const upload = multer({ storage });

// Endpoint for uploading files to database
app.post("/upload", upload.single("file"), (req, res) => {
  // res.json({ file: req.file });
  res.redirect("/");
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When there is an error or no matching HTTP method, Next.js API routes will provide a default response

Currently, I am diving into the world of API Routes in Next.js where each path is structured like this: import { NextApiRequest, NextApiResponse } from "next"; export default async (req: NextApiRequest, res: NextApiResponse) => { const { qu ...

Alert: Refs cannot be assigned to function components. Any attempt to access this ref will result in failure. Have you considered using React.forwardRef()? displayed in the @Mui Component

Is anyone familiar with this particular component? <Controller control={control} {...register("DOB", {})} render={({ field }) => ( <LocalizationProvider dateAdapter={AdapterDayjs}> <DatePicker ...

Japanese Character File Naming Convention

When dealing with certain Japanese characters, the content disposition header appears as follows: Content-Disposition: attachment; filename=CSV_____1-___.csv; filename*=UTF-8''CSV%E3%82%A8%E3%83%93%E3%83%87%E3%83%B3%E3%82%B91-%E3%82%B3%E3%83%94%E ...

Verify whether an email is already registered in firestore authentication during the signup process using Angular

When a user signs up for our app, I want them to receive immediate feedback on whether the email they are attempting to sign up with already exists. Currently, the user has to submit the form before being notified if the email is taken or not. This desire ...

Developing a custom package containing personally crafted type definitions and importing them into the project

I'm in need of creating a private npm package specifically for custom type definitions (typedefs) that are hand-written d.ts files not generated by TypeScript. Since these are proprietary, they cannot be added to DefinitelyTyped. The folder structure ...

Error: Unable to retrieve value of variable ('fname') as it is undefined

This image is sourced from bootstrap Everything appears fine in this image. I am unable to identify the problem which is hindering me from solving it. ...

Nvm does not have the ability to generate an Angular project

Creating an Angular project using nvm has been a bit of a challenge for me. Here are the steps I took: D:\Project1>nvm list The output showed: 14.16.1 Next, I ran the following command. F:\Ashok\Angular\Angular>nvm use 14.16.1 ...

Trouble with Next Js Image 'fill' property causing images to not show up on the page

Currently tackling a project involving a simple grid layout with images and text. I'm using Next 13.4.7 along with Tailwind CSS. However, I've encountered an issue when trying to import an image using the Next Image component with the fill prop - ...

Every time I try to send a post request including a cookie in Axios, I encounter

I recently sent a POST request from localhost including a Cookie using Axios, but I received a 405 Method Not Allowed error. Below is the source code of my request: axios .post( 'http://10.xxx.13.xxx/api/seller/register', { partn ...

Troubleshooting a 400 error with the Stripe Webhook due to problems with the raw

After diligently following Stripes documentation on setting up webhooks and testing locally using their Stripe CLI, I have encountered a persistent issue. While I can successfully create events, I consistently receive a response of 400 POST. 2021-12-14 23: ...

React: The Material-UI autocomplete input, controlled with the React Hook Form `<controller>` component, experiences issues when the `multiple` prop is set to `true`

Currently facing challenges with managing an autocomplete MUI component using the <controller> component in react-hook-form. Take a look at the code snippet below: <Controller control={control} name="rooms" render={({ field }) =&g ...

The setter function for a boolean value in React's useState hook is malfunctioning

I encountered an issue while trying to update a state value using its setter from the useState hook. Surprisingly, the same setter worked perfectly in a different function where it set the value to true. To confirm that the function call was correct, I te ...

Styling Dropdown Options Based on Conditions in React

In my current project, I am attempting to modify the className of selected items within a mapped array using another array (this.props.notPressAble). The reason for this is because I want certain objects in the array to have a different CSS style. handleOp ...

The destination path specified in npm copyfiles is not accurate

Currently, I am utilizing the npm package known as "copyfiles" within my buildscript. However, I have noticed that the target directory does not match the expected output. "copy-template": "copyfiles \"./src/**/*.html\" \"dist\"", The ...

Self-signed certificate encountered in the certificate chain for Node-Postgres

I am encountering an issue while attempting to connect to my Azure Postgres instance using the node-postgres (pg) module. The error message I receive indicates a Self signed certificate in the certificate chain. Interestingly, I can successfully connect u ...

Optimizing Angular.js templates for faster loading using Node.js pre-compilation

As I delve into learning Angular and integrating it with my current Node.js framework, I find myself facing some challenges. Previously, I utilized Handlebars.js as my templating engine in Node.js, where I would build the context on the server side and the ...

Create a custom file uploading feature in React with Material-UI

I am currently working on developing a compact file upload component. Previously, I utilized the <input type="file"> tag but due to limited space constraints, I need to display both "Choose file" and the complete file path within a very sma ...

Is there a way to spy on private functions within a node module using jasmine-node?

mainApp.js function _hidden() { console.log( '_hidden' ); } function show() { console.log( 'showing' ); _hidden(); } module.exports = { show: show, _hidden: _hidden }; test/mainTest.js describe( 'testing&ap ...

Identifying asynchronous JavaScript and XML (AJAX) requests using Express in NodeJS

When working with NodeJS and Express, I am wondering how to distinguish between a regular browser request and an AJAX request. I understand that one approach is to inspect the request headers, but I am curious if Node/Express provides direct access to th ...

When utilizing the http.post method, the req.body is not being populated as expected

I am puzzled by the fact that the req.body appears to be empty... app.js utilizes the body-parser middleware() var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var index = require('./routes/in ...