Kong / httpsnippet

HTTP Request snippet generator for many languages & libraries
Apache License 2.0
1.14k stars 226 forks source link

Specifying file mime type for multipart requests using python requests module #302

Open Accumulative opened 2 years ago

Accumulative commented 2 years ago

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;
}
joebullard commented 1 year ago

bump