-
Notifications
You must be signed in to change notification settings - Fork 4
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
(#265): async image upload example - fully working #18
base: main
Are you sure you want to change the base?
Conversation
response_name="UploadStatus", | ||
request_stream=True, | ||
) | ||
async def UpdateImage(self, request, context): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UploadImage may be a better name
request_name="FileChunk", | ||
response=[{"name": "success", "type": "bool"}], | ||
response_name="UploadStatus", | ||
request_stream=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not using a response stream too to send upload progress ?
|
||
queryset = self.get_queryset() | ||
|
||
book = await sync_to_async(queryset.get)(book_id=book_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
book = await queryset.aget(book_id=book_id)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually if you use the lookupfield in the request (remplacing book_id by just id) you can directly do something like:
book = await self.aget_object()
book = await sync_to_async(queryset.get)(book_id=book_id) | ||
|
||
print("----- found:", book.title) | ||
res = await sync_to_async(book.image.save)(filename, f, save=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
res = await book.image.asave(filename, f, save=True)
Hi @AMontagu and @legau,
after a long search, I finally managed to build a working example of an Image Upload and Update.
The sync_to_async part still looks a little bit clumsy - is there a nicer way to formulate it ?
If not, please merge it into master and correct the documentation.
Merci.