Skip to content

Commit

Permalink
Add all_files to support multiple file uploads in names ending with [] (
Browse files Browse the repository at this point in the history
  • Loading branch information
sdogruyol authored Jan 15, 2025
1 parent 5359781 commit 369371b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/kemal/param_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 369371b

Please sign in to comment.