From b81ff8f424d191125d96ec2fae1865f5a3725977 Mon Sep 17 00:00:00 2001 From: Niklas Mollenhauer Date: Tue, 19 Nov 2019 21:39:47 +0100 Subject: [PATCH] [restify] Use formidable file type for file uploads (#40391) * Use formidable file type for file uploads * Remove triple-slash import --- types/restify/index.d.ts | 10 +++------- types/restify/restify-tests.ts | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/types/restify/index.d.ts b/types/restify/index.d.ts index cdc27253e9..8e44d5d3aa 100644 --- a/types/restify/index.d.ts +++ b/types/restify/index.d.ts @@ -17,6 +17,7 @@ import url = require('url'); import spdy = require('spdy'); import stream = require('stream'); import zlib = require('zlib'); +import { File } from 'formidable'; export interface ServerOptions { ca?: string | Buffer | ReadonlyArray; @@ -418,11 +419,6 @@ export class Router { strictNext: boolean; } -export interface RequestFileInterface { - path: string; - type: string; -} - export interface RequestAuthorization { scheme: string; credentials: string; @@ -644,8 +640,8 @@ export interface Request extends http.IncomingMessage { /** available when queryParser or bodyParser plugin is used with mapParams enabled. */ params?: any; - /** available when serveStatic plugin is used. */ - files?: { [name: string]: RequestFileInterface }; + /** available when multipartBodyParser plugin is used. */ + files?: { [name: string]: File | undefined; }; /** available when authorizationParser plugin is used */ username?: string; diff --git a/types/restify/restify-tests.ts b/types/restify/restify-tests.ts index b81ecfebd1..ff0ffdc70c 100644 --- a/types/restify/restify-tests.ts +++ b/types/restify/restify-tests.ts @@ -143,6 +143,7 @@ server.use(restify.plugins.queryParser()); server.use(restify.plugins.jsonp()); server.use(restify.plugins.gzipResponse()); server.use(restify.plugins.bodyParser()); +server.use(restify.plugins.multipartBodyParser()); server.use( restify.plugins.serveStaticFiles('somePath', { etag: '1', @@ -172,6 +173,19 @@ server.use(restify.plugins.conditionalHandler([{ version: '0.0.0', }])); +server.post("/test-files", (req, res, next) => { + const files = req.files; + if (files) { + const testFile = files["test"]; + if (testFile) { + console.log(testFile.path); + console.log(testFile.name); + console.log(testFile.size); + } + } + next(); +}); + const logger = Logger.createLogger({ name: "test" }); server.on('after', restify.plugins.auditLogger({ event: 'after', log: logger }));