Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload file (e.g. image) with multipart reader get empty payload #3301

Closed
lomoonmoonbird opened this issue Sep 29, 2018 · 2 comments
Closed

Comments

@lomoonmoonbird
Copy link

Long story short

I am implementing an upload file system, user selects file in html and click upload ,aiohttp server receive and store it in filesystem. thats it.

accroding to [https://docs.aiohttp.org/en/stable/web_quickstart.html#file-uploads](aiohttp official method)

the first method with request handler that reads whole payload worked, but second with multipart reader didnt work.

Expected behaviour

multipart reader reads payload and save file in filesystem

Actual behaviour

multipart reader received nothing

Steps to reproduce

html:

<strong>Upload</strong>
<form method="post" action="http://localhost:52789/api/admin/image/poster/upload" enctype="multipart/form-data">
    <strong>Choise files: </strong> <input type="file" name="filename" >
    <input type="submit" name="sender" value="Send" />
</form>

server:

async def post_image(self, request):

       reader = await request.multipart()
       
       image = await reader.next()
       print (await image.read(decode=True)) #this printed bytearray of file content
       filename = image.filename
       print (filename) # this printed file name
       size = 0
       with open(os.path.join('', filename), 'wb') as f:
           while True:
               chunk = await image.read_chunk()
       
               print ("chunk", chunk) $ chunk is empty
               if not chunk:
                   break
               size += len(chunk)
               f.write(chunk)
       return await self.reply_ok({"a":"b"})

http request:
POST /api/admin/image/poster/upload HTTP/1.1
Host: localhost:52789
Connection: keep-alive
Content-Length: 27023
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: null
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryB6BTxs8E0K6dZVpG
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: Admin-Token=admin; sidebarStatus=1

Your environment

python: 3.6
aiohttp:2.3.7
chrome:69.0.3497.100

@aio-libs-bot
Copy link

GitMate.io thinks the contributors most likely able to help are @asvetlov, and @kxepal.

Possibly related issues are #490 (Don't work "multipart/form-data" file upload.), #436 (Request.GET drops empty params), #1067 (will there be huge file upload support ?), #3090 (Remove reader parameter from request.multipart()), and #3034 (Multipart file form data with name).

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants