"stream" in put vs request.FILES['file']

17 views
Skip to first unread message

Kishor Pawar

unread,
Feb 14, 2018, 6:36:22 AM2/14/18
to Django REST framework
So I wanted to write a custom file upload parser as specified in docs

According to doc I implemented the "parsemethod as 

----------------------------488071469102781097692083 Content-Disposition: form-data; name="file"; filename="email_test.msg" Content-Type: application/vnd.ms-outlook < actual content here > ----------------------------488071469102781097692083--

class MailParser(BaseParser):
   
"""
        parses email serialized data
    """



    media_type
= "multipart/form-data"


   
def parse(self, stream, media_type = None, parser_context = None):
       
""" Here I was trying to read stream """


but when I tried to read stream it additionally had following content

    ----------------------------488071469102781097692083
    Content-Disposition: form-data; name="file"; filename="email_test.msg"
    Content-Type: application/vnd.ms-outlook  

   < actual content here >

    ----------------------------488071469102781097692083--

But when I directly read the file from request using 

request.FILES['file'] .read()

The same content wasn't there.

I wanted to understand this behaviour.

Thanks in advance.
Reply all
Reply to author
Forward
0 new messages