Giter VIP home page Giter VIP logo

Comments (11)

m0uneer avatar m0uneer commented on September 17, 2024 1

Hi @Romakita , how can Multer configuration be passed? I see that the only config available is the uploadDir through server settings.

from tsed.

Romakita avatar Romakita commented on September 17, 2024 1

Hi @m0uneer ,

Actually, global settings let you to customize the uploadDir. For more, options you need to give that to the MultipartFile decorators.

@MultipartFile(multerOptions)

See you

from tsed.

naoric avatar naoric commented on September 17, 2024 1

Solved by installing @tsed/multipartfiles and

import { MultipartFile } from '@tsed/multipartfiles'

In the documentation, @tsed/multipartfile is mentioned instead of @tsed/multipartfiles (plural)
And it looks like it should be used only for multiple files upload.

https://romakita.github.io/ts-express-decorators/#/tutorials/upload-files-with-multer?id=example

from tsed.

Romakita avatar Romakita commented on September 17, 2024 1

Hum ok. I'll fix this typo :) Thanks @naoric

from tsed.

Romakita avatar Romakita commented on September 17, 2024
@Controller('/')
class MyCtrl {
     @Post('/file')
     private uploadFile(@MultipartFile() file: Multer.File) {

     }

     @Post('/files')
     private uploadFile(@MultipartFile() files: Multer.File[]) {

     }
}

from tsed.

khusamov avatar khusamov commented on September 17, 2024

Hello! And where does the class Multer.File come from?

The https://romakita.github.io/ts-express-decorators/#/tutorials/upload-files-with-multer?id=example page does not describe where the Multer.File class comes from and the decorator @ MultipartFile.

from tsed.

Romakita avatar Romakita commented on September 17, 2024

Hi @khusamov ,

Multer come from the @types/multer and the decorator come from 'ts-express-decorators'.

Sorry, I'll fix the documentation soon :)

from tsed.

khusamov avatar khusamov commented on September 17, 2024

Thanks for the answer!

In the file @types/multer/index.d.ts I found only interface Express.Multer.File (line 99). But I can not understand how to connect it (with import).

I found how to connect the decorator MultipartFile with the help ofimport {MultipartFile} from 'ts-express-decorators / multipartfiles';. At you on a site in the documentation it is passed (

from tsed.

Romakita avatar Romakita commented on September 17, 2024

Hello @khusamov ,

Sorry for this mistake. I've just found the right example on my old project:

import {Controller, Post} from "ts-express-decorators";
import {Multer} from "@types/multer";

type MulterFile = Express.Multer.File;

@Controller('/')
class MyCtrl {
    
  @Post('/file')
  private uploadFile(@MultipartFile() file: MulterFile) {

  }
     
  @Post('/file')
  private uploadFile(@MultipartFile({dest: "/other-dir"}) file: MulterFile) {
         
  }
}

It works normally :)
See you !

from tsed.

Romakita avatar Romakita commented on September 17, 2024

Documentation will be updated soon ;)

from tsed.

naoric avatar naoric commented on September 17, 2024

@MultipartFile still not recognized, used the code from the documentation:

import { Controller, Get, Post } from '@tsed/common'
import Multer from 'multer'

type MulterFile = Express.Multer.File

export interface ViewerModel {
  name: string
  file: string
}

@Controller('/models')
export class ViewerModelCtrl {
  @Get('/')
  async renderModels() {
    return 'Hello World'
  }

  @Post('/')
  private uploadeModel(@MultiplartFile() file: MulterFile) {}
}

I get 'Cannot find name 'MultipartFile'

from tsed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.