Files support in `Request.blank` method

Create issue
Issue #15 resolved
Tim Perevezentsev created an issue

How do you test files upload?

Comments (10)

  1. Tim Perevezentsev reporter

    I suppose the following behavior:

    Form POST (no files)

    >>> request = Request.blank('/', POST={'name': 'value'})
    >>> request.content_type # 'application/x-www-form-urlencoded'
    >>> request.body # 'name=value'
    

    Form POST (with files)

    >>> request = Request.blank('/', POST={'file': ('filename', file_like_obj)})
    >>> request.content_type # 'multipart/form-data'
    >>> request.body
    'Content-Type: multipart/form-data; boundary=AaB03x
    
    --AaB03x
    Content-Disposition: form-data; name="file"; filename="filename"
    Content-Type: text/plain
    
       ... contents ...
    --AaB03x--'
    

    Form POST (no files) with content type provided in `headers` keyword

    >>> request = Request.blank('/', POST={'name': 'value'}, 
    ...                              headers={'Content-Type': 'multipart/form-data'})
    >>> request.content_type # 'multipart/form-data'
    >>> request.body
    'Content-Type: multipart/form-data; boundary=AaB03x
    
    --AaB03x
    Content-Disposition: form-data; name="name";
    
    value
    --AaB03x--'
    

    Form POST (with files) with content type provided in `headers` keyword

    >>> request = Request.blank('/', POST={'file': ('filename', file_like_obj)}, 
    ...                              headers={'Content-Type': 'application/x-www-form-urlencoded'})
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: read rfc (or something like this)
    
  2. Sergey Schetinin
    • changed status to open

    That API is reasonable, if you have a patch, I would accept it (preferably including full test coverage).

    Another thing that was talked about for a while is our intention to have req.FILES or similar which would include just the file uploads. So setting it / passing it to .blank(..) would accomplish the same thing. I don't have time to implement it for now, so it's hard to tell when it will be available.

  3. Sergey Schetinin

    It's a decent implementation, but it lasks the setter. Also, we will probably will stop depending on cgi.FieldStorage and parse the stream ourselves.

  4. Tim Perevezentsev reporter

    I've forked project and implemented this issue in a new branch (parent commit is 1.0.8). What branch do I `pull request` to? `default` or new branch?

  5. Sergey Schetinin

    First, pull and merge the changes from the main repo, then file a request to default branch.

  6. Tim Perevezentsev reporter
    • changed status to open

    One more thing. As you can see in tests, we can post data with `put` method. So is it normal to use argument name `POST` in `BaseRequest.blank`? May be rename it to `data` or something else?

  7. Sergey Schetinin

    We have to keep backwards compat and if we consider the deprecation process I don't think it's worth it.

    Are you sure this issue is not resolved?

  8. Log in to comment