medusa icon indicating copy to clipboard operation
medusa copied to clipboard

Issue with UTF-8 characters in filename

Open ddanninger opened this issue 11 months ago • 1 comments

Bug report

Describe the bug

Broken filenames, when uploading filenames with non ascii characters as media / thumbnail.

System information

Medusa version (including plugins): 1.20.2 Node.js version: v18.18.0 Database: postgres Operating system: windows

Steps to reproduce the behavior

  1. Go to Product Detail
  2. Upload Testfile 테스트-강아지.jpg

Screenshots

screenshot-response screenshot-body

Code snippets

Temporary fix by overwriting the route and use multer-utf8

api/middlewares.ts

import type { MiddlewaresConfig } from "@medusajs/medusa";
import multer from "multer-utf8";

const upload = multer({
  dest: "uploads/",
  charset: "utf8",
});

export const config: MiddlewaresConfig = {
  routes: [
    {
      matcher: "/admin/uploads",
      middlewares: [upload.array("files")], // OVERWRITE ADMIN UPLOAD DUE UTF8 ISSUE
    },
    {
      matcher: "/admin/uploads/protected",
      middlewares: [upload.array("files")], // OVERWRITE ADMIN UPLOAD DUE UTF8 ISSUE
    },
  ],
};

api/admin/uploads/route.ts

import createUpload from "@medusajs/medusa/dist/api/routes/admin/uploads/create-upload";

export const POST = createUpload;

api/admin/uploads/protected/route.ts

import createProtectedUpload from "@medusajs/medusa/dist/api/routes/admin/uploads/create-protected-upload";

export const POST = createProtectedUpload;

Additional Context

  • https://github.com/expressjs/multer/issues/1104

ddanninger avatar Mar 11 '24 16:03 ddanninger