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

Specific ordering of duplicate key names for multipart data. #663

Open
tom-asmblr opened this issue May 13, 2021 · 1 comment · May be fixed by httprb/form_data#32
Open

Specific ordering of duplicate key names for multipart data. #663

tom-asmblr opened this issue May 13, 2021 · 1 comment · May be fixed by httprb/form_data#32

Comments

@tom-asmblr
Copy link

Hi, thanks for the great project.

I'm working with an API that requires multiple files to be uploaded such that the file metadata is followed by the file stream, repeating, with each metadata part having the name='metadata' and each file part having the name 'file' For instance, to upload two files:

Data: -----------------------1ca273...
Content-Disposition: form-data; name="metadata"

{"filename":"Report One.pdf","documentType":"Report"}
-----------------------1ca2...
Content-Disposition: form-data; name="file"; filename="stream-70139852475000"
Content-Type: application/pdf
(data for file one)
-----------------------abcdef1...
Content-Disposition: form-data; name="metadata"

{"filename":"Report Two.pdf","documentType":"Report"}
-----------------------efacd...
Content-Disposition: form-data; name="file"; filename="stream-70139852475000"
Content-Type: application/pdf
(data for file two)

Having duplicate file names seems odd, but as far as I can see in the spec it's supported, the spec also mentions maintaining the order of the parts.

Obviously using a hash to the pass in the keys doesn't work, as ruby can't have duplicate keys in a hash:

{
  metadata: '{}',
  file: '...',
  metadata: '{}',
  file: '..'
}

I've found doing the following does add all four parts, however, the order is metadata, metadata, file, file, which the API does not accept.

{
  metadata: ['{}', '{}'],
  file: ['...', '...']
}

Any idea if what I need is possible?

Thanks!

@ixti
Copy link
Member

ixti commented May 19, 2021

Yeah, that's doable - we will need to improve https://github.com/httprb/form_data/blob/master/lib/http/form_data/multipart.rb to accept an array pairs instead:

form: [
  ['metadata', '{}'],
  ['file', '...'],
  # ...
]

ixti added a commit to httprb/form_data that referenced this issue May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants