I need to create a POST where I can upload multiple files in the same request, but I don't know how to write this with grape. Right now to upload just one file this is what I'm doing and It's working fine:
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 it's not looking fine:
Also I tried:
params do
optional :attachments, type: Array do
requires :file, :type => Rack::Multipart::UploadedFile, :desc => "Attachment File."
end
end
Not a good result either.
What's the right way of handling this?