ruby-grape / ruby-grape/grape

Endpoints expecting `multipart/related`?

Open
#1,020 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discuss! feature request
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

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! 🐈

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the documented multipart POST and PUT behavior, then inspect the endpoint handling described in the issue, including params, env['api.request.body'], and env['api.request.input']. Compare the multipart/form-data example with the reported multipart/related request containing metadata and file parts. Done means establishing whether multipart/related is supported or documenting the intended limitation and available integration path.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.