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
				
			
		|  | @ -1,4 +1,5 @@ | |||
| require "http" | ||||
| require "multipart" | ||||
| require "./kemal/*" | ||||
| require "./kemal/helpers/*" | ||||
| require "./kemal/middleware/*" | ||||
|  |  | |||
|  | @ -39,7 +39,7 @@ module Kemal | |||
|     end | ||||
| 
 | ||||
|     def configure_ssl | ||||
|     {% if ! flag?(:without_openssl) %} | ||||
|       {% if !flag?(:without_openssl) %} | ||||
|       if @ssl_enabled | ||||
|         puts "SSL Key Not Found"; exit unless @key_file | ||||
|         puts "SSL Certificate Not Found"; exit unless @cert_file | ||||
|  |  | |||
|  | @ -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…
	
	Add table
		Add a link
		
	
		Reference in a new issue