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

Reading multipart form data with text fields #3619

Closed
parthibd opened this issue Feb 21, 2019 · 5 comments
Closed

Reading multipart form data with text fields #3619

parthibd opened this issue Feb 21, 2019 · 5 comments

Comments

@parthibd
Copy link

parthibd commented Feb 21, 2019

I was able to read a file using multipart reader. How do I extract text fields? I am lost. An example would be really helpful.

@aio-libs-bot
Copy link

GitMate.io thinks the contributor most likely able to help you is @asvetlov.

Possibly related issues are #3034 (Multipart file form data with name), #903 (How to pass array to form data (multipart/form-data)), #304 (multipart tests), #880 (MultipartReader does not support multipart data with a preamble), and #490 (Don't work "multipart/form-data" file upload.).

@kornicameister
Copy link
Contributor

When you're reading a file using multipart reader you most likely referenced that file by name. That's how multipart work AFAIR, you're labelling parts in entire multipart. The text fields ought have the names as well.

Given you used web_request.Request#post coroutine for that you ought to get the values of the fields from returned dictionary. If you're using web_request.Request#mutlipart you got to traverse all the parts manually looking for the one that has the name you're interested in the moment.

@parthibd
Copy link
Author

Thanks a lot for the solution . I had to manually traverse all the parts to extract them out from the request . My problem is solved . :)

@kornicameister
Copy link
Contributor

kornicameister commented Feb 25, 2019

Just so you know, using post couroutine comes with the price. If there's a file sent you may face a larger memory usage as the file is being loaded behind the scenes for you. That's why when it comes to files you might want to use async for or next on the reader you obtained via multipart looking for fields manually. That's of course valid only if you have a chance to not read an entire file and for instance write portion of bytes in chunks to the server filesystem. Otherwise I guess there are other concepts like restricting the size of the file via content-length. Although, AFAIR, there's an entry in code or documentation that says that content-lenght might not be reliable when it comes to larger, perhaps only, files.

I'd assume that @asvetlov or someone else from core team might be able to shed more light here, if you're interested of course :)

@parthibd
Copy link
Author

Thanks for the heads up. :) I did notice sluginess when I was looking through the fields containing larger files. I'm using async for for this purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants