I need to create a POST where I can upload multiple files to the same request, but I donβt know how to write this using grapes. Right now, to upload only one file, this is what I am doing and it works great:
desc 'Creates a new attachment.' params do requires :file, :type => Rack::Multipart::UploadedFile, :desc => "Attachment File." end post do attachment = Attachment.new attachment.file = ActionDispatch::Http::UploadedFile.new(params[:file]) attachment.save! attachment end
Swagger shows me this:

I was thinking of doing something like this:
desc 'Creates a new attachment.' params do requires :file, :type => Array[Rack::Multipart::UploadedFile], :desc => "Attachment File." end
But this does not look good:

Also I tried:
params do optional :attachments, type: Array do requires :file, :type => Rack::Multipart::UploadedFile, :desc => "Attachment File." end end
Not a very good result.

What is the right way to handle this?
source share