django celery - 如何将 request.FILES['photo'] 发送到任务

发布于 2024-10-05 16:45:22 字数 226 浏览 0 评论 0原文

我正在尝试通过以下方式将 request.FILES['photo'](从我的网站上传的文件)发送到 tCelery:

tasks.upload_photos.delay(img=request.FILES['photo'])

我收到 pickle 错误,因为它无法序列化它。向任务发送文件的方式是什么?

错误:“无法腌制 StringO 对象” 谢谢。

i'm trying to send request.FILES['photo'], an uploaded file from my site, to tCelery via:

tasks.upload_photos.delay(img=request.FILES['photo'])

I get a pickle error because it cannot serialize it. What is the way to send a file to task?

error: "can't pickle StringO objects"
thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

征棹 2024-10-12 16:45:22

将文件内容读取到字符串中,然后将其与内容类型一起打包到字典中并发送。

Read the file contents into a string, then pack it with the content type in a dict and send that.

旧故 2024-10-12 16:45:22

如果您计划保存文件,可以将文件保存到模型,然后将 id/pk 传递给 celery 任务。

If you plan on saving the file, you can save the file to a model, then pass the id/pk to a celery task.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文