-
Notifications
You must be signed in to change notification settings - Fork 184
Streaming file upload is not working #433
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
Comments
|
I have enabled bebug logs. Expanding the input argument does not work because create mutation only accepts input as ProductDocumentCreateMutationInput. I have shared the schema below. Also file upload works when only So I tried following 3 things:
Relevant Schema:
|
It should always be possible to expand input types into GraphQL basic types and scalars.
with the That being said, your problem seems quite strange.
|
Could you share a working code for streaming file upload if you have?
With
|
You can find some examples in the tests/test_aiohttp.py file. Search for You can run specific tests by running a pytest command like this:
Check out the test_aiohttp_async_generator_upload test.
That is what we are doing. gql is open-source you know, you can check the code.
gql uses the I thought you could do something like: f = open('filepath', 'rb)
f.name = "your_name"
data = {
"user": 'user_id',
"file_category": 'product_doc',
"file": f,
} but in that case I got the error:
So one way to change the filename would be what you did above, even if it's a bit inefficient: file = io.BytesIO(open(filepath, "rb").read())
file.name = "your_name" In the case of the streaming uploads, we have the same kind of problem. async_generator = file_sender(file_path)
async_generator.name = "your_name" would generate the following error:
We can get around by making a new class inheriting class NamedAsyncGenerator(collections.abc.AsyncGenerator):
name = None
inner_generator = None
def __init__(self, inner_generator: collections.abc.AsyncGenerator, name=None):
self.inner_generator = inner_generator
self.name = name
def asend(self, val):
return self.inner_generator.asend(val)
def athrow(self, typ, val):
return self.inner_generator.athrow(typ, val) that you would use like this: async def file_sender(file_name):
async with aiofiles.open(file_name, "rb") as f:
chunk = await f.read(64 * 1024)
while chunk:
yield chunk
chunk = await f.read(64 * 1024)
async_generator = file_sender(file_path)
named_async_generator = NamedAsyncGenerator(async_generator, "your_filename")
data = {
"user": 'user_id',
"file_category": 'product_doc',
"file": named_async_generator,
} I agree that's it's not really clean and we should consider changing the interface to make this simpler. |
@leszekhanusz FYI, your workaround gives error Whenever I add the generator |
That error message is coming from the backend. |
I wanted to open an issue regarding the filename but than I found this discussion. You already pointed to the line where you could fix it by removing the explicit setting of |
@RainerHausdorf It's a bit off-topic in this issue but you should check the PR #549 which should set the |
Uh oh!
There was an error while loading. Please reload this page.
In above I am trying to stream file upload as shown in the
gql
documentation. But I get following errorSystem info:
The text was updated successfully, but these errors were encountered: