rubyrackwebmachine

(Multipart) zip upload in ruby webmachine handled by rack


I'm making an upload form for zips in a ruby webmachine app. My idea is to have an upload through my backend where I can add some extra params and then upload it to amazons s3 service with RestClient.

I did successfully create a direct upload (web based form post) to a s3bucket, but in that way I'm unable to handle the variables which are needed in the request, the way I want.

I've tried several things but I can't figure out, how to handle the request, as soon as it gets in my backend. I've created a resource and I'm debugging directly in the process_post method.

My @request variable represents a Webmachine::Request, with a Webmachine::Adapters::Rack::RequestBody and a Rack::Request, but I can't get the file out of it to use it as input for my RestClient request.

I think; @request.body.to_s and @request.body.to_io, represent the uploaded file in some way, and I tried to use them as input for Rack::Multipart methods, but that doesn't give me the file.

I also tried to work with the rack-raw-upload gem, but I can't get the mime-type something else than "application/x-www-form-urlencoded" or multipart. I do explicitly set it to; application/octet-stream

Things like File.new(filename, 'rb') gave me `rrno::ENOENT: No such file or directory @ rb_sysopen'. For filename I just used 'example.zip'.

I guess I'm missing something which has to do with the Rack::Request call(env) method.

Does somebody have an idea, on how to handle the Rack uploads? Or give me any hints for a new direction? Thanks.


Solution

  • I've created a gist which shows how to retrieve the multipart stream. You'll need further parsing in order to get the uploaded file.

    https://gist.github.com/jewilmeer/eb40abd665b70f53e6eb60801de24342