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

request.files in addition to request.data #1651

Closed
ilkarman opened this issue Feb 17, 2017 · 11 comments
Closed

request.files in addition to request.data #1651

ilkarman opened this issue Feb 17, 2017 · 11 comments
Labels

Comments

@ilkarman
Copy link

It seems the only way to add files to a request with aiohttp is by referencing them in the data parameter. However this becomes problematic when you have an API that expects to see something in 'files', not 'data.

For example, this works (using requests):

files = {'imagefile': open(fname, 'rb')}
requests.post(url, files=files)

However this doesnt:

files = aiohttp.FormData()
files.add_field('imagefile', open(fname, 'rb'))
response = yield from s.request('post', url, data=files)
@AraHaan
Copy link
Contributor

AraHaan commented Feb 17, 2017

So, what you need is an files= parameter for request?

@AraHaan
Copy link
Contributor

AraHaan commented Feb 17, 2017

I created an PR that adds that parameter however I have not implemented the usage of it fully yet until I find out more on how requests works on it.

@AraHaan
Copy link
Contributor

AraHaan commented Feb 17, 2017

I have void the github repo for the requests package I am looking into how they implemented their files= on it to hopefully add it into aiohttp.

@AraHaan
Copy link
Contributor

AraHaan commented Feb 17, 2017

Ok, @iksteen I am working on it to where this would work for you (or at least something of the similar):

files = {'imagefile': open(fname, 'rb')}
response = yield from s.request('post', url, files=files)

@fafhrd91
Copy link
Member

i do not think files= is good idea.

maybe something like aiohttp.request(data=FormData(File('file.name'), File(fileObject, filename=''), Stream(streamReader))) etc

@AraHaan
Copy link
Contributor

AraHaan commented Feb 20, 2017

@ilkarman doe's @fafhrd91 comment help fix this issue?

@asvetlov
Copy link
Member

IIRC we had files param but it was too ambiguous.
Let's think about API changing very carefully.
Personally I feel a need for sleeping on it before next discussion iteration.

@fafhrd91
Copy link
Member

I agree, we need to think about this api carefully. I envision some UploadItem interface that we can use as data value or as argument to FormData which in turn can implement UploadItem interface. it has to support sizable/unsizable stream types. also we should be able to use it in aiohttp.web as well.

@fafhrd91
Copy link
Member

better name is PayloadItem

@fafhrd91
Copy link
Member

@asvetlov let's move conversation to #1172

@lock
Copy link

lock bot commented Oct 29, 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.

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

No branches or pull requests

4 participants