4

我正在使用Joi来验证请求。我想知道如何使用 Joi 验证上传的文件大小。

我将许多文件作为流发送。

4

1 回答 1

6

To limits the size of incoming payloads to the specified byte count you can use as follow:

route.options.payload.maxBytes

for example:

      payload: {
          maxBytes: 20715200,
          output: 'stream',
          parse: true,
          allow: 'multipart/form-data'
      },
      validate: {
          payload: {
                bannerImage: Joi.any()
                .meta({swaggerType: 'file'})
                .optional()
                .allow('')
                .description('image file'),
                   },
          failAction: UniversalFunctions.failActionFunction
      },
  • Default value will be 1048576 (1MB).
  • Allowing very large payloads may cause the server to run out of memory.
于 2018-06-27T05:36:41.177 回答