Skip to content
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

[docs] examples/with-multer #143

Open
leeuwis opened this issue May 20, 2021 · 3 comments
Open

[docs] examples/with-multer #143

leeuwis opened this issue May 20, 2021 · 3 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@leeuwis
Copy link
Member

leeuwis commented May 20, 2021

Using the new middleware decorators

@leeuwis leeuwis changed the title [docs] example/with-multer [docs] examples/with-multer May 20, 2021
@leeuwis leeuwis added the documentation Improvements or additions to documentation label Sep 18, 2021
@crivera
Copy link

crivera commented Apr 22, 2022

Hi

just for future reference


import {
  Body,
  createHandler,
  HttpCode,
  Post,
  UploadedFiles,
  UseMiddleware,
} from "@storyofams/next-api-decorators"
import multer from "multer"

const upload = multer({
  dest: "uploads/",
  limits: {
    fileSize: 52428800,
  },
}).array("files")

class DocumentsHandler {
  @Post()
  @HttpCode(201)
  @UseMiddleware(upload)
  public async create(@Body() body, @UploadedFiles() files: any) {
    console.log(body.test)
    console.log(files)
    return {}
  }
}

export default createHandler(DocumentsHandler)

export const config = {
  api: {
    bodyParser: false, // Disallow body parsing, consume as stream
  },
}

and your form

<form action="/api/documents" enctype="multipart/form-data" method="post">

    <input type="file"name="files">
    <input type="text"  name="test">
    <input type="submit">            

</form>

@galmatn
Copy link

galmatn commented May 30, 2022

Take into consideration that the bodyParser: false will affect any other endpoint that you could add later in this handler (I'm dealing with this right now)

@GreccoOliva-Franco
Copy link

@galmatn That's exactly what I'm experiencing right now. Any updates on handling some endpoints with multer and others with bodyParser?

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

No branches or pull requests

5 participants