Celery task for file uploading in django wizard

懵懂的女人 提交于 2019-12-11 18:18:47

问题


I have a WizardView covering two forms, the second one has a FileField. Is it possible to create a Celery task for uploading a file from that FileField?

Should I create another FILE_UPLOAD_HANDLER? All the information concerning handling files using wizard I found at https://docs.djangoproject.com is about having to add a file_storage to the WizardView subclass.


回答1:


Actually uploading a file is a request, therefore you need to handle it with a view and then do whatever you want to do, including starting a celery task to handle file manipulation. The problem with that approach is the inability to serve a regular response to client if celery task returns something (but you can, for example, ping a special url from client side periodically or use socket.io to deliver the results).

One thing doesn't change - file upload, whether separate or within a regular form, is a request, and therefore you must first handle it with a view and only afterwards may pass received data to a task or handle it directly.

Further on, file upload handlers deal with receiving data from socket. I guess you could create one working in a celery task, or rather tasks, due to partial nature of data sent through sockets, but as far as I know your form data couldn't be accessed before the file is uploaded anyway (or in the better case, you can access all data but the file), so there is no point in sending it to celery, especially if you need to create a response involving some manipulation on the file.



来源:https://stackoverflow.com/questions/16108704/celery-task-for-file-uploading-in-django-wizard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!