Skip to content

Multipart files tweaks - #482

Merged
yeraydiazdiaz merged 5 commits into
encode:masterfrom
yeraydiazdiaz:multipart-files-tweaks
Oct 20, 2019
Merged

Multipart files tweaks#482
yeraydiazdiaz merged 5 commits into
encode:masterfrom
yeraydiazdiaz:multipart-files-tweaks

Conversation

@yeraydiazdiaz

Copy link
Copy Markdown
Contributor

Fixeshttps://github.com/encode/httpx/issues/481

The tuple values of the files dictionary passed to multipart_encode now support:

  • None filenames, the header will not include the filename section
  • str objects as the contents, as opposed to file-like objects

I wasn't sure about adding docs about it as requests seems to not include it and it seemed more of an implementation detail that doesn't quite fit in the quickstart guide. But I'm happy to include it if we think it's worth it.

@yeraydiazdiaz
yeraydiazdiaz requested a review from a teamOctober 18, 2019 19:27
@florimondmanca

Copy link
Copy Markdown
Contributor

Nice work @yeraydiazdiaz! I might be in favor of a files section in the advanced docs. :)

@sethmlarsonsethmlarson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks @yeraydiazdiaz!

@florimondmancaflorimondmanca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as well, just a minor typo nit. :)

Comment threaddocs/advanced.md Outdated
Co-Authored-By: Florimond Manca <florimond.manca@gmail.com>
@yeraydiazdiaz
yeraydiazdiaz merged commit 9ec2cfc into encode:masterOct 20, 2019
@yeraydiazdiaz
yeraydiazdiaz deleted the multipart-files-tweaks branch October 20, 2019 12:25
@yeraydiazdiaz

Copy link
Copy Markdown
ContributorAuthor

Thanks all! 💚

Comment threaddocs/advanced.md
"files": {},
"form": {
"upload-file": "text-content"
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused by this example - wouldn't we expect the item to be in "files" here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused about that too.

That's the actual output of httpbin, the headers we send are correct as shown in the tests and I verified requests gets the same output from httpbin so I left it as is.

It's a bit confusing for the docs, maybe we should show the request headers instead of the response from httpbin?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably just omit that example, since:

  1. We can't really walk the user through "btw the server appears to have a weird implementation where it puts files into "form" if they're unnamed.
  2. Sending unnamed files isn't a prefered usage.

I guess you could verify the behavior against say, Starlette, just to check that we really are doing the right thing, but not fussed if that's too onerous, since we're checking in our tests.

Kludex referenced this pull request in pydantic/httpx2 May 11, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

HTTP Post with files works with Requests but not HTTPX

4 participants

@yeraydiazdiaz@florimondmanca@lovelydinosaur@sethmlarson