Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoints expecting multipart/related? #1020

Open
NobodysNightmare opened this issue May 29, 2015 · 2 comments
Open

Endpoints expecting multipart/related? #1020

NobodysNightmare opened this issue May 29, 2015 · 2 comments

Comments

@NobodysNightmare
Copy link

Hi,

from reading the docs I could find out that grape basically seems to support multiple multipart content types, including multipart/related.

However, the relevant section of the documentation just reads:

Multipart POSTs and PUTs are supported as well.

The request:

curl --form image_file='@image.jpg;type=image/jpg' http://localhost:9292/upload

The Grape endpoint:

post "upload" do
  # file in params[:image_file]
end

I see how that is working for multipart/form-data and it works beautiful for that Content-Type.
However, at the moment I am not sure if that is the right thing to do for an API that is free of classical HTML forms. That is why I thought about using multipart/related instead, expecting a first part with some metadata and a second part with the actual contents of the file (which is btw. the same thing Google Drive does).

However, it is not yet clear to me how that would be possible using grape. When receiving such a request:

  • the params do not contain anything except an id and route_info
  • env['api.request.body'] is nil
  • env['api.request.input'] is nil

Thus I don't see which options I would have to implement such an endpoint using Grape.

Is this a known/intended limitation?
Am I doing it wrong?

Any help is apprechiated.

Best regards and thanks for taking the time to review this issue! 🐈

@dblock
Copy link
Member

dblock commented May 29, 2015

I think it's not natively supported by Rack, so you might need rack-multipart_related, try adding it ahead of Grape (config.ru)? I would appreciate it if you could please add a demo with tests to https://github.com/dblock/grape-on-rack.

@NobodysNightmare
Copy link
Author

I'll see if I can get it running using rack-multipart_related in my spare time.
For now I have chosen the path of least resistance and use multipart/form-data in the API. I fear that clients will face similar difficulties with their libraries when I would force them to not use multipart/form-data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants