Uh oh!
There was an error while loading. Please reload this page.
Streaming multipart uploads (httpcore) - #863
Conversation
…ng-httpcore-multipart
When dropping the Anyway, here's an update on server compatibility:
(I tried a full-blown Django project instead, but still no luck. I get a message like Script>>>importhttpx>>>defupload(url): ... lorem=open("debug/lorem.txt") ... files= {"lorem": lorem} ... data= {"hello": "world"} ... returnhttpx.post(url, data=data, files=files) ...HTTPBin>>>url="https://httpbin.org/post">>>r=upload(url)
>>>r.json() # Contains correct "files" and "data"Django microserver# app.pyimportjsonfromdjango.confimportsettingsfromdjango.core.handlers.wsgiimportWSGIHandlerfromdjango.httpimportHttpResponsefromdjango.urlsimportpathsettings.configure(ROOT_URLCONF=__name__,)
defupload_file(request):
print(request.body) # XXX: this is b""... not sure why.content= {
"method": request.method,
"headers": dict(request.headers),
"data": dict(request.POST),
"files": dict(request.FILES),
}
returnHttpResponse(json.dumps(content), content_type="application/json")
urlpatterns= [path("", upload_file)]
app=WSGIHandler()uvicorn app:app --interface wsgi>>>url="http://localhost:8000">>>r=upload(url)
>>>r.json() # XXX: "data" and "files" and emptyStarlette# app.pyfromstarlette.applicationsimportStarlettefromstarlette.routingimportRoutefromstarlette.responsesimportJSONResponsefromstarlette.requestsimportRequestfromstarlette.datastructuresimportUploadFileasyncdefupload(request: Request):
form=dict(awaitrequest.form())
hello: str=form["hello"]
lorem: UploadFile=form["lorem"]
content= {
"data": {"hello": hello},
"files": {"lorem": (awaitlorem.read()).decode()},
}
returnJSONResponse(content)
routes= [Route("/", upload, methods=["POST"])]
app=Starlette(routes=routes)uvicorn app:app>>>url="http://localhost:8000">>>r=upload(url)
>>>r.json() # Contains correct "files" and "data" |
OK so, a small improvement for Django is to use the Still, … then stops as there's no body to read: Not sure if this is a bug in Django, but it's a hint that support for multipart uploads w/o So, cutting to the chase, I think we should:
The cases when a file-like object doesn't have a measurable length are so small I think we're good enough with this approach for now. i.e. we almost always will include a |
florimondmanca
commented
Mar 13, 2020
Closing as it's not strictly required for us to have the |
Bumps [mypy](https://github.com/python/mypy) from 1.7.1 to 1.8.0. - [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md) - [Commits](python/mypy@v1.7.1...v1.8.0) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Variant of #857 rebased against #804