mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Simplify file upload parsing and support multiple uploads with same name (#458)
This commit is contained in:
		
							parent
							
								
									f916bad095
								
							
						
					
					
						commit
						eed97877a7
					
				
					 2 changed files with 22 additions and 2 deletions
				
			
		
							
								
								
									
										20
									
								
								CHANGELOG.md
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								CHANGELOG.md
									
										
									
									
									
								
							|  | @ -1,3 +1,23 @@ | ||||||
|  | # Next | ||||||
|  | 
 | ||||||
|  | - `env.params.files` is now an `Array(FileUpload)`. You can iterate over to access the images. | ||||||
|  | 
 | ||||||
|  | ```ruby | ||||||
|  | env.params.files.each do |file| | ||||||
|  | 
 | ||||||
|  |   filename = file.filename | ||||||
|  | 
 | ||||||
|  |   if !filename.is_a?(String) | ||||||
|  |     "No filename included in upload" | ||||||
|  |   else | ||||||
|  |     file_path = ::File.join [Kemal.config.public_folder, "uploads/", filename] | ||||||
|  |     File.open(file_path, "w") do |f| | ||||||
|  |     IO.copy(file.tmpfile, f) | ||||||
|  |   end | ||||||
|  |   "Upload OK" | ||||||
|  | end | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
| # 0.23.0 (17-06-2018) | # 0.23.0 (17-06-2018) | ||||||
| 
 | 
 | ||||||
| - Crystal 0.25.0 support 🎉 | - Crystal 0.25.0 support 🎉 | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ module Kemal | ||||||
|       @query = HTTP::Params.new({} of String => Array(String)) |       @query = HTTP::Params.new({} of String => Array(String)) | ||||||
|       @body = HTTP::Params.new({} of String => Array(String)) |       @body = HTTP::Params.new({} of String => Array(String)) | ||||||
|       @json = {} of String => AllParamTypes |       @json = {} of String => AllParamTypes | ||||||
|       @files = {} of String => FileUpload |       @files = [] of FileUpload | ||||||
|       @url_parsed = false |       @url_parsed = false | ||||||
|       @query_parsed = false |       @query_parsed = false | ||||||
|       @body_parsed = false |       @body_parsed = false | ||||||
|  | @ -71,7 +71,7 @@ module Kemal | ||||||
|         next unless upload |         next unless upload | ||||||
|         filename = upload.filename |         filename = upload.filename | ||||||
|         if !filename.nil? |         if !filename.nil? | ||||||
|           @files[upload.name] = FileUpload.new(upload: upload) |           @files << FileUpload.new(upload: upload) | ||||||
|         else |         else | ||||||
|           @body.add(upload.name, upload.body.gets_to_end) |           @body.add(upload.name, upload.body.gets_to_end) | ||||||
|         end |         end | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue