interagent / interagent/committee

Add support for 'multipart/form-data' file upload

Open
#255 5 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ready
Dominant language
Ruby
Stars
955
Forks
145
Avg merge
5d 4h
Merged PRs (30d)
6

Description

I'm attempting to describe file upload, according to swagger docs for file-upload we should define the file as type string with the format of binary.

so my openapi for this request looks like:

      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                contractId:
                  type: string
                  example: 270A2087-6335-455E-B32D-350C00FFEEB7
                organisationId:
                  description: Your ID for this participant
                  example: AAA123
                  type: string
                resourceId:
                  type: string
                  example: 49E2797A-A62E-4042-9587-2CC0A1DBC679
                file:
                  type: string
                  format: binary

However by the time this gets to the committee middleware rack has exploded the file to a hash

file: {
  :filename=>"i_am_a_file.csv", 
  :type=>"text/plain", 
  :name=>"file", 
  :tempfile=>#<Tempfile:/tmp/RackMultipart20200306-13-1rx39tl.csv>, 
  :head=>"Content-Disposition: form-data; name=\"file\"; filename=\"i_am_a_file.csv\"\r\nContent-Type: text/plain\r\nContent-Length: 81\r\n"
}

so we end up with an error like:

#/paths/~1api~1v1~1telemetry_data_files/post/requestBody/content/multipart~1form-data/schema/properties/file expected string, but received Hash:

I was looking at test/request_unpacker_test.rb but I do not see how to handle this situation. What am I missing?

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 test/request_unpacker_test.rb and trace how the multipart/form-data request body is unpacked before schema validation. Reproduce the OpenAPI example with Rack's file hash, then determine the expected representation for the file field. Done means the described upload no longer fails with an expected-string-but-received-Hash error.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.