1. Ian Bicking
  2. WebOb
  3. Issues
Issue #15 resolved

Files support in `Request.blank` method

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. 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?

  4. Log in to comment