DRF和芹菜:filenotfounderror:[errno 2]没有此类文件或目录
这在我的本地部署上正常工作,但在云部署上效果不佳。
with open(file_path, "wb+") as fp:
for chunk in file:
fp.write(chunk)
result = upload.delay(name, file_path)
在另一个文件中:
@shared_task
def upload(name, file_path):
path = Path(path_tmp)
if os.path.isfile(path):
do something
错误是
不是路径/媒体/介质/rawfiles/file.png”, FILENOTFOUNDERROR:[ERRNO 2]没有此类文件或目录
当我在docker中导航到 - > /mediafiles/rawfiles
,该文件在那里并且具有大小。
我正在使用drf->芹菜 - > Django。
有人可以帮助为什么云部署无法找到该文件?
This works fine on my local deployment but on the cloud deployement it does not.
with open(file_path, "wb+") as fp:
for chunk in file:
fp.write(chunk)
result = upload.delay(name, file_path)
In a different file:
@shared_task
def upload(name, file_path):
path = Path(path_tmp)
if os.path.isfile(path):
do something
The error is
Not a path /mediafiles/rawfiles/file.png",
FileNotFoundError: [Errno 2] No such file or directory
When I navigate in the docker to -> /mediafiles/rawfiles
, the file is there and has a size.
I am using DRF -> Celery -> Django.
Can someone help why the cloud deployment is not able to find the file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您使用
@shared_task
将任务委派给芹菜工人并尝试访问文件系统时,它会尝试在工作机器上获取此文件。因此,您需要使用文件或将目标文件复制到Worker Machine上的机器上执行此任务。
When you delegate task to celery worker with
@shared_task
and try to get access to the filesystem, it try to get this file on the worker machine.So you need to execute this task on machine with a file or copy target file to worker machine.
我将 workdir 添加到start CMD,然后效果很好。
希望有帮助。
I add workdir to the start cmd, then it works well.
Hope that helps.