uploading image files inside consumers.py with Django-Channels #2138
Replies: 3 comments
-
Hey there, I've taken a look at your code and have a few suggestions that might help resolve the issues you’re facing: first you have one typo:
corrected:
File Writing:Using 'ab' to append binary chunks is a good start. However, consider how you’ll determine when the full image has been received. You might need to implement a protocol for signaling the start and end of the file transfer (e.g., sending metadata indicating chunk boundaries or a final chunk). synchronous File I/O:Although for small files synchronous writes can be acceptable, if you expect any scale or larger file sizes in the future, exploring asynchronous file handling could be beneficial. Other Consideration:File Naming & Extension:The file is currently saved as uploaded_image.jgp. You probably want to change the extension to .jpg, and to avoid conflicts (especially in multi-user scenarios), generate a unique filename per upload. |
Beta Was this translation helpful? Give feedback.
-
Okay I fixed the syntax errors you mentioned. How should I go about the file handling, that is integrating a protocol for signaling start/end of file transfer to the frontent? Are there any links you can provide me? Also some resource links for asynchronous file handling? I've heard that importing |
Beta Was this translation helpful? Give feedback.
-
Here is my edited consumers.py
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I need some help with implementing uploading/receiving image files between end-users with Django-Channels/Websockets inside Consumers.
Here are my consumers.py and also I'm using VueJS as the frontend.
Sorry I'm still new to Django-Channels/Websockets. The files uploaded (images) don't need to be large in bytes. Please let me know if you to see additional relevant files in my Django project
Beta Was this translation helpful? Give feedback.
All reactions