mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	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: |   kilt: | ||||||
|     github: jeromegn/kilt |     github: jeromegn/kilt | ||||||
|     version: 0.3.3 |     version: 0.3.3 | ||||||
|  |   multipart: | ||||||
|  |     github: RX14/multipart.cr | ||||||
|  |     version: 0.1.0 | ||||||
|  | 
 | ||||||
| author: | author: | ||||||
|   - Serdar Dogruyol <dogruyolserdar@gmail.com> |   - Serdar Dogruyol <dogruyolserdar@gmail.com> | ||||||
|  |  | ||||||
|  | @ -135,7 +135,7 @@ describe "Macros" do | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   describe "#serve_static" do |   describe "#serve_static" do | ||||||
|     it "should disble static file hosting" do |     it "should disable static file hosting" do | ||||||
|       serve_static false |       serve_static false | ||||||
|       Kemal.config.serve_static.should eq false |       Kemal.config.serve_static.should eq false | ||||||
|     end |     end | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| require "http" | require "http" | ||||||
|  | require "multipart" | ||||||
| require "./kemal/*" | require "./kemal/*" | ||||||
| require "./kemal/helpers/*" | require "./kemal/helpers/*" | ||||||
| require "./kemal/middleware/*" | require "./kemal/middleware/*" | ||||||
|  |  | ||||||
|  | @ -39,7 +39,7 @@ module Kemal | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     def configure_ssl |     def configure_ssl | ||||||
|     {% if ! flag?(:without_openssl) %} |       {% if !flag?(:without_openssl) %} | ||||||
|       if @ssl_enabled |       if @ssl_enabled | ||||||
|         puts "SSL Key Not Found"; exit unless @key_file |         puts "SSL Key Not Found"; exit unless @key_file | ||||||
|         puts "SSL Certificate Not Found"; exit unless @cert_file |         puts "SSL Certificate Not Found"; exit unless @cert_file | ||||||
|  |  | ||||||
|  | @ -78,3 +78,20 @@ end | ||||||
| def gzip(status : Bool = false) | def gzip(status : Bool = false) | ||||||
|   add_handler HTTP::DeflateHandler.new if status |   add_handler HTTP::DeflateHandler.new if status | ||||||
| end | 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…
	
	Add table
		Add a link
		
	
		Reference in a new issue