Skip to main content
 首页 » 编程设计

python之上传的文件/ block 正在消失

2024年12月31日9bluestorm

我正在尝试使用 resumable.js 和 django 设置大型文件上传系统。前端都已正确配置,对于我使用的 django 端 django-resumable .我正在使用一个非常基本的 View 来处理上传:

from resumable.views import ResumableUploadView 
from django.conf import settings 
from django.core.exceptions import ImproperlyConfigured 
 
class UserFileUploadView(ResumableUploadView): 
    @property 
    def chunks_dir(self): 
        chunks_dir = getattr(settings, 'MEDIA_ROOT', None) 
        if not chunks_dir: 
            raise ImproperlyConfigured( 
                'You must set settings.MEDIA_ROOT') 
        return chunks_dir 

当我上传一个文件时,它似乎上传正确,但我在 MEDIA_ROOT 目录中看不到 block 或完整的文件。
如果我取消上传,服务器有时会提到一个 ConnectionAbortedError 和一些 AttributeErrors ,并且开始新的上传会忽略所有上传的 block 。如果允许上传完成,则在页面刷新之前我无法再次上传文件。

在翻看django-resumable代码,我明白它应该如何运作,但看不出有任何理由不应该这样做。有什么方法可以确定 block 是否正在上传,如果正在上传,它们会去哪里?

请您参考如下方法:

原来是路由的问题。我正在使用 JSON Web Tokens 进行身份验证,但上传 View 的路径使用了 login_required(),这似乎不起作用。我似乎还错误地提供了我的 JWT,使用的是 token: 字段而不是 Authentication: header 。