Type of object received during file upload using @UploadFile

孤街醉人 提交于 2019-12-02 12:25:56

You can save the file by specifying a destination path in the MulterOptions:

// files will be saved in the /uploads folder
@UseInterceptors(FileInterceptor('file', {dest: 'uploads'}))

If you want more control over how your file is saved, you can create a multer diskStorage configuration object instead:

import { diskStorage } from 'multer';

export const myStorage = diskStorage({
  // Specify where to save the file
  destination: (req, file, cb) => {
    cb(null, 'uploads');
  },
  // Specify the file name
  filename: (req, file, cb) => {
    cb(null, Date.now() + '-' + file.originalname);
  },
});

And then pass it to the storage property in your controller.

@UseInterceptors(FileInterceptor('file', {storage: myStorage}))

For more configuration options, see the multer docs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!