Specifying file mime type for multipart requests using python requests module

Open
#302 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
python, typescript
Domain
api, tooling

Research direction

Start in src/targets/python/requests/client.ts around line 82 and inspect how multipart files are assembled for Python requests snippets. Compare the current file handling with the proposed MIME-type behavior, then check nearby tests or target fixtures if present. Done means a file parameter with a MIME type produces the requested multipart tuple while existing file and payload handling remains unchanged.

Written by the indexing model from the issue text.

Description

I'm unable to specify the mime type of the files sent as part of multipart/form-data requests using the python requests module.

I believe the relevant code is here: https://github.com/Kong/httpsnippet/blob/master/src/targets/python/requests/client.ts#L82

I was thinking we could support it by making a change like so:

if (p.fileName) {
  if (p.mimeType) {
     files[p.name] = `('${p.fileName}', open('${p.fileName}', 'rb'), '${p.mimeType}')`;
  } else {
     // current behaviour
     files[p.name] = `open('${p.fileName}', 'rb')`;
  }
  hasFiles = true;
} else {
  payload[p.name] = p.value;
  hasPayload = true;
}
Dominant language
TypeScript
Stars
1.2k
Forks
242
PR merge metrics
No merged PRs in 30d

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.

More from Kong/httpsnippet

All issues in Kong/httpsnippet

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.