From 369371bb83e06570dc6964c0e164ffe3aadd6367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Serdar=20Dogruyol=20-=20Sedo=20=E3=82=BB=E3=83=89?= <990485+sdogruyol@users.noreply.github.com> Date: Wed, 15 Jan 2025 15:44:39 +0300 Subject: [PATCH] Add all_files to support multiple file uploads in names ending with [] (#701) --- src/kemal/param_parser.cr | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/kemal/param_parser.cr b/src/kemal/param_parser.cr index 5d87ba0e..8d937769 100644 --- a/src/kemal/param_parser.cr +++ b/src/kemal/param_parser.cr @@ -9,13 +9,14 @@ module Kemal PARTS = %w(url query body json files) # :nodoc: alias AllParamTypes = Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Any) | Array(JSON::Any) - getter files + getter files, all_files def initialize(@request : HTTP::Request, @url : Hash(String, String) = {} of String => String) @query = HTTP::Params.new({} of String => Array(String)) @body = HTTP::Params.new({} of String => Array(String)) @json = {} of String => AllParamTypes @files = {} of String => FileUpload + @all_files = {} of String => Array(FileUpload) @url_parsed = false @query_parsed = false @body_parsed = false @@ -71,11 +72,17 @@ module Kemal next unless upload filename = upload.filename + name = upload.name if !filename.nil? - @files[upload.name] = FileUpload.new(upload) + if name.ends_with?("[]") + @all_files[name] ||= [] of FileUpload + @all_files[name] << FileUpload.new(upload) + else + @files[name] = FileUpload.new(upload) + end else - @body.add(upload.name, upload.body.gets_to_end) + @body.add(name, upload.body.gets_to_end) end end