Search code examples
httpfile-uploadcrystal-langkemal

Crystal-lang file/image upload http server


Is it possible to have a crystal based web server which handles file upload? I have been looking in the docs, and in many of the crystal web frameworks. I have not found any reference to a simple file upload feature anywhere.

Is this possible, or do I have to look elsewhere to handle my image-uploads?


Solution

  • UPDATED ANSWER: As of November 2016 you can use Kemal v0.16.1 and Crystal 0.19.4 for File uploads.

    Here's how you can use it

    post "/upload" do |env|
      parse_multipart(env) do |f|
        image1 = f.data if f.field == "image1"
        image2 = f.data if f.field == "image2"
        puts f.meta
        puts f.headers
        "Upload complete"
      end
    end