Skip to content

[Bug]: Image size limit extremely low Admin Ui uploads #12117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
iaachboun opened this issue Apr 8, 2025 · 3 comments
Open

[Bug]: Image size limit extremely low Admin Ui uploads #12117

iaachboun opened this issue Apr 8, 2025 · 3 comments

Comments

@iaachboun
Copy link

iaachboun commented Apr 8, 2025

Package.json file

{
  "name": "flamingowonen",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "predeploy": "medusa db:migrate"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "2.5.1",
    "@medusajs/cli": "^2.6.1",
    "@medusajs/framework": "^2.6.1",
    "@medusajs/medusa": "^2.6.1",
    "@medusajs/payment": "^2.6.1",
    "@medusajs/payment-stripe": "^2.6.1",
    "@mikro-orm/core": "6.4.3",
    "@mikro-orm/knex": "6.4.3",
    "@mikro-orm/migrations": "6.4.3",
    "@mikro-orm/postgresql": "6.4.3",
    "awilix": "^8.0.1",
    "crypto-random-string": "^5.0.0",
    "pg": "^8.13.0",
    "stripe": "^17.7.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "2.5.1",
    "@mikro-orm/cli": "6.4.3",
    "@swc/core": "1.5.7",
    "@swc/jest": "^0.2.36",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.0.0",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.4.15",
    "yalc": "^1.0.0-pre.53"
  },
  "engines": {
    "node": ">=18"
  }
}

Node.js version

v20.17.0

Database and its version

6.4.3

Operating system name and version

Ubuntu 20.04.6 LTS

Browser name

Google Chrome

What happended?

Image

Image

Image

When i upload really small images like under 4kb they get uploaded but anything bigger i get those following errors.

Anyone know why? is there a default file limit?

Expected behavior

Uploading of all images

Actual behavior

Also i noticed when the small iamges are uploaded i see somehting in the server logs happening, but with the failing bigger images nothing comes in. like the backend server is not even being reached.

Link to reproduction repo

@iaachboun
Copy link
Author

iaachboun commented Apr 8, 2025

I saw in medusa docs that i should add a middleware to increase the default 100kb size

import { defineMiddlewares } from "@medusajs/framework/http"
import multer from "multer"

// Define the upload variable before using it
const upload = multer({ storage: multer.memoryStorage() })

export default defineMiddlewares({
routes: [
{
method: ["POST"],
bodyParser: { sizeLimit: "10mb" },
matcher: "/admin/uploads",
middlewares: [
// @ts-ignore
upload.array("files"),
],
},
],
})

Image

This is what i have but doesnt work either

@Vallabh-Mahanta
Copy link
Contributor

I've been investigating this image upload issue and have some insights that may help.

After testing in my environment, I noticed that properly configured database and cache connections are critical for handling larger file uploads. When these services aren't properly synchronized or configured, it appears the upload process fails early with very small size limits.

To address this and similar environment-related issues, I've already submitted a Docker-based solution in PR #12182 and #12181 that:

  1. Ensures proper synchronization between all services (backend, database, cache)
  2. Configures the environment correctly for file uploads
  3. Prevents test-related issues (like those in [Bug]: Unit tests prevent application from running #12163) from interfering with development
  4. Provides a consistent environment across all development machines
  5. Ensures service synchronization with automatic retries until connections succeed
  6. Isolates the environment to prevent test interference issues
  7. Orchestrates proper startup sequence with dependency health checks
  8. Provides a single-command development environment setup

For this specific image upload issue, the solution requires configuring both:

  • The body parser limit.
  • The multer file size limit.

I'd be happy to submit a separate PR specifically for this upload size issue if the team would find that helpful. The Docker solution I've already submitted would help ensure developers don't encounter these types of environment sync issues in the future, as everything is properly configured and synchronized out of the box with a simple docker-compose up command.

Would appreciate any feedback from the Medusa team and contributors on either approach.

@TKasperczyk
Copy link

TKasperczyk commented Apr 21, 2025

One way to solve that would be to introduce a custom middleware config:

// src/api/middlewares.ts
import { defineMiddlewares } from "@medusajs/framework/http"
import type { MiddlewaresConfig } from "@medusajs/framework"

const UPLOAD_SIZE_LIMIT = "10mb";

export const config: MiddlewaresConfig = {
  routes: [
    {
      matcher: "/admin/uploads",
      method: ["POST"],
      bodyParser: {
        sizeLimit: UPLOAD_SIZE_LIMIT,
      },
      middlewares: [],
    },
  ],
}

export default config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants