fastify-multer
Advanced tools
Comparing version 1.5.2 to 1.5.3
@@ -43,5 +43,7 @@ "use strict"; | ||
if (this.request.files[file.fieldname]) { | ||
; | ||
this.request.files[file.fieldname].push(placeholder); | ||
} | ||
else { | ||
; | ||
this.request.files[file.fieldname] = [placeholder]; | ||
@@ -48,0 +50,0 @@ } |
{ | ||
"name": "fastify-multer", | ||
"description": "Fastify plugin for handling `multipart/form-data`.", | ||
"version": "1.5.2", | ||
"version": "1.5.3", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "types": "lib/", |
![Logo](https://user-images.githubusercontent.com/6388707/66124653-463a2d00-e5e5-11e9-8fed-b5bca26b66ea.png) | ||
[![NPM Version](https://badgen.net/npm/v/fastify-multer)](https://www.npmjs.com/package/fastify-multer) [![GitHub CI](https://github.com/fox1t/multer/workflows/ci/badge.svg)](https://github.com/fox1t/multer/actions) ![npm download](https://img.shields.io/npm/dt/fastify-multer) ![David](https://img.shields.io/david/fox1t/multer) ![GitHub last commit](https://img.shields.io/github/last-commit/fox1t/multer) ![GitHub](https://img.shields.io/github/license/fox1t/multer) | ||
[![NPM Version](https://badgen.net/npm/v/fastify-multer)](https://www.npmjs.com/package/fastify-multer) [![GitHub CI](https://github.com/fox1t/fastify-multer/workflows/ci/badge.svg)](https://github.com/fox1t/fastify-multer/actions) ![npm download](https://img.shields.io/npm/dt/fastify-multer) ![David](https://img.shields.io/david/fox1t/fastify-multer) ![GitHub last commit](https://img.shields.io/github/last-commit/fox1t/fastify-multer) ![GitHub](https://img.shields.io/github/license/fox1t/fastify-multer) | ||
@@ -54,2 +54,13 @@ # Fastify Multer | ||
// or using the short hand declaration | ||
server.post( | ||
'/profile', | ||
{ preHandler: upload.single('avatar') }, | ||
function(request, reply) { | ||
// request.file is the `avatar` file | ||
// request.body will hold the text fields, if there were any | ||
reply.code(200).send('SUCCESS') | ||
} | ||
) | ||
server.route({ | ||
@@ -56,0 +67,0 @@ method: 'POST', |
@@ -15,3 +15,3 @@ import { IncomingMessage } from 'http' | ||
export function isMultipart(this: FastifyRequest<IncomingMessage>): boolean { | ||
return this.req[kMultipart] || false | ||
return (this.req as any)[kMultipart] || false | ||
} | ||
@@ -18,0 +18,0 @@ |
import { FastifyRequest } from 'fastify' | ||
import { File } from '../interfaces' | ||
import { File, FilesObject } from '../interfaces' | ||
@@ -53,6 +53,6 @@ export type Strategy = 'NONE' | 'VALUE' | 'ARRAY' | 'OBJECT' | ||
case 'OBJECT': | ||
if (this.request.files[file.fieldname]) { | ||
this.request.files[file.fieldname].push(placeholder) | ||
if ((this.request.files as FilesObject)[file.fieldname]) { | ||
;(this.request.files as FilesObject)[file.fieldname].push(placeholder) | ||
} else { | ||
this.request.files[file.fieldname] = [placeholder] | ||
;(this.request.files as FilesObject)[file.fieldname] = [placeholder] | ||
} | ||
@@ -74,6 +74,6 @@ break | ||
case 'OBJECT': | ||
if (this.request.files[placeholder.fieldname].length === 1) { | ||
delete this.request.files[placeholder.fieldname] | ||
if ((this.request.files as FilesObject)[placeholder.fieldname].length === 1) { | ||
delete (this.request.files as FilesObject)[placeholder.fieldname] | ||
} else { | ||
arrayRemove(this.request.files[placeholder.fieldname], placeholder) | ||
arrayRemove((this.request.files as FilesObject)[placeholder.fieldname], placeholder) | ||
} | ||
@@ -80,0 +80,0 @@ break |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
79233
1422
318