Add multipart support <3
This commit is contained in:
parent
ad9790b9d8
commit
7efe69ac31
5 changed files with 24 additions and 2 deletions
|
@ -8,5 +8,9 @@ dependencies:
|
|||
kilt:
|
||||
github: jeromegn/kilt
|
||||
version: 0.3.3
|
||||
multipart:
|
||||
github: RX14/multipart.cr
|
||||
version: 0.1.0
|
||||
|
||||
author:
|
||||
- Serdar Dogruyol <dogruyolserdar@gmail.com>
|
||||
|
|
|
@ -135,7 +135,7 @@ describe "Macros" do
|
|||
end
|
||||
|
||||
describe "#serve_static" do
|
||||
it "should disble static file hosting" do
|
||||
it "should disable static file hosting" do
|
||||
serve_static false
|
||||
Kemal.config.serve_static.should eq false
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require "http"
|
||||
require "multipart"
|
||||
require "./kemal/*"
|
||||
require "./kemal/helpers/*"
|
||||
require "./kemal/middleware/*"
|
||||
|
|
|
@ -78,3 +78,20 @@ end
|
|||
def gzip(status : Bool = false)
|
||||
add_handler HTTP::DeflateHandler.new if status
|
||||
end
|
||||
|
||||
# Parses a multipart/form-data request. This is really useful for file uploads.
|
||||
# Consider the example below taking two image uploads as image1, image2. To get the relevant data
|
||||
# for each field you can use simple `if/switch` conditional.
|
||||
#
|
||||
# post "/upload" do |env|
|
||||
# parse_multipart(env) do |field, data|
|
||||
# image1 = data if field == "image1"
|
||||
# image2 = data if field == "image2"
|
||||
# "Upload complete"
|
||||
# end
|
||||
# end
|
||||
def parse_multipart(env)
|
||||
HTTP::FormData.parse(env.request) do |field, data|
|
||||
yield field, data
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue