twisted / twisted/klein

Handle uploading multiple files

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

Nobody has claimed this yet.

feature
Dominant language
Python
Stars
838
Forks
123
Avg merge
7h 58m
Merged PRs (30d)
12

Description

Tornado, Flask, Django, and most current web frameworks allows for convenient functions for uploading files to the backend. Klein should handle file uploads in a similar fashion as well. Here's a quick example of how it could work:

@route('/')
def example(request):
    # example Request.files
    file_0 = request.files['my_files'][0]
    file_1 = request.files['my_files'][1]

    # example of what a "HTTP File" object would contain
    file_0.filename  # str
    file_0.content    # BytesIO

This issue cannot be addressed without bringing up the infamous Issue 288. There are some great ideas in the comments of that issue. One comment suggests processing args after the request object has been created. Building upon that, we should be able to implement a solution for files (at one point when tx.web2 was a thing, it seems that this was a possible). This would involve extending web.Request or creating a Klein specific Request component. I'm just throwing this idea up here in case anyone has suggestions or has anything.

As a contingency plan, another utility function could be created and it could replicate, for instance, what Tornado does for files.

from klein.utils import fileinfo
my_file = fileinfo(request.args[b'my_file'][0])
print( my_file.filename )
print( my_file.content )
References

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.

Research direction

Start with the linked Twisted Issue 288 and the existing web.Request handling; the issue does not name specific Klein files or tests. Compare the proposed request.files interface with the alternative klein.utils.fileinfo approach and the referenced framework behavior. Done means Klein has a decided, tested way to expose multiple uploaded files with filename and content.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.