Tsed: [BUG] storage._handleFile is not a function

Created on 17 Mar 2020  路  6Comments  路  Source: tsedio/tsed

Information

  • Version: 5.x
  • Packages:
    "@types/multer": "^1.3.9",
    "@tsed/multipartfiles": "^5.41.2",
    "multer": "1.4.2",

I set option @ServerSetings

    {
        multer: {
        storage: handleStorage(),
    }

With handleStore function will return multer.StorageEngine, but I when upload is error and crash node

bug released

Most helpful comment

Fixed :)

All 6 comments

Hello @thanhchuongitc
Can you give a repository with a reproductible example please.
I haven't enough information to reproduct your problem.

See you
Romain

The same thing happened to me, I had to pass the storage function directly to the controller, because as a global function it doesn't work. I guess it should be fixed, while you can do it on the controller:

import { MulterOptions, MultipartFile } from '@tsed/multipartfiles'
import { diskStorage } from 'multer';

const storage = diskStorage({
  destination: function (req, file, cb) {
    cb(null, './public/uploads/profiles')
  },
  filename: function (req, file, cb) {
    cb(null, file.originalname)
  }
});

  @Post('/upload/:id')
  @Description('Upload image profile by user ID')
  @MulterOptions({ storage: storage })
  async upload (@MultipartFile('image') image, @PathParams('id') id): Promise<any> {
    const user = await this.userRepository.findOne(id);
    if (!user) {
      throw new NotFound('Not user found')
    }
    user.image = '/uploads/profiles/' + image.originalname;
    return this.userRepository.save(user);

  }

The same thing happened to me, I had to pass the storage function directly to the controller, because as a global function it doesn't work. I guess it should be fixed, while you can do it on the controller:

import { MulterOptions, MultipartFile } from '@tsed/multipartfiles'
import { diskStorage } from 'multer';

const storage = diskStorage({
  destination: function (req, file, cb) {
    cb(null, './public/uploads/profiles')
  },
  filename: function (req, file, cb) {
    cb(null, file.originalname)
  }
});

  @Post('/upload/:id')
  @Description('Upload image profile by user ID')
  @MulterOptions({ storage: storage })
  async upload (@MultipartFile('image') image, @PathParams('id') id): Promise<any> {
    const user = await this.userRepository.findOne(id);
    if (!user) {
      throw new NotFound('Not user found')
    }
    user.image = '/uploads/profiles/' + image.originalname;
    return this.userRepository.save(user);

  }

Thank you, I fixed it

I keep this issue open. I'll fix this ASAP

:tada: This issue has been resolved in version 5.44.14 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

Fixed :)

Was this page helpful?
0 / 5 - 0 ratings