Hey
I have a slice with a JSON Rest API. So the main actions format is :json
. In this api i also need an endpoint to upload files. Because of this I cannot set config.actions.format :json
at the slice config. If I do it, I get an Unsupported Media Type
response.
module Documents
class Slice < Hanami::Slice
# config.actions.format :json
config.db.import_from_parent = true
end
end
module MyDocumentsApp
class Routes < Hanami::Routes
# Add your routes here. See https://guides.hanamirb.org/routing/overview/ for details.
slice :documents, at: "/documents" do
scope "upload" do
use :body_parser, :form
post ":folder", to: "upload"
end
scope "api" do
use :body_parser, :json
post "users", to: "api.users.create"
end
end
end
end
I tried to set explicitly set the action format at the Upload-Action
module Documents
module Actions
class Upload < Documents::Action
config.formats.add :multipart, "multipart/form-data"
config.format :multipart
def handle(req, res)
# ...
end
end
end
end
but still get the Unsupported Media Type
response. The only solution at the moment is that I do not set the format at slice-config level. In the upload action, I am not allowed to set a custom format.
Do you know a better solution?
thanks