@sdogruyol sdogruyol released this Feb 11, 2017 · 178 commits to master since this release

Assets 2
  • Simpler file upload. File uploads can now be accessed from HTTP::Server::Context like env.params.files["filename"].

env.params.files["filename"] has 5 methods

  • tmpfile: This is temporary file for file upload. Useful for saving the upload file.
  • tmpfile_path: File path of tmpfile.
  • filename: File name of the file upload. (logo.png, images.zip e.g)
  • meta: Meta information for the file upload.
  • headers: Headers for the file upload.

Here's a fully working sample for reading a image file upload image1 and saving it under public/uploads.

post "/upload" do |env|
  file = env.params.files["image1"].tmpfile
  file_path = ::File.join [Kemal.config.public_folder, "uploads/", file.filename]
  File.open(file_path, "w") do |f|
    IO.copy(file, f)
  "Upload ok"

To test

curl -F "image1=@/Users/serdar/Downloads/kemal.png" http://localhost:3000/upload