几天前,库下载了django-chunked-upload
,使用 Django 将大文件上传到多个部分,并且它可以工作。
但是我必须为用户添加一个进度条来查看充电过程,似乎它的目的是使 jQuery-File-upload
工作,但不知道如何实现它。
当您下载django-chunked-upload
的演示时是一个示例,但该示例不会将数据保存到数据库中。
问题
我需要有人帮助我提供一个如何使用 django-chunked-upload 和 jQuery-file-upload 上传大文件的示例,并将其保存在数据库或告诉我一种使用带有进度条的 Django
上传大文件的方法。
最佳答案
django-chunked-upload-demo是您真正需要使用 django-chunked-upload 的示例。所以问题仍然是
When you download the demo of django-chunked-upload is an example but this example does not save data in the database.
如果您在 django-chunked-uplad-demo.demo.views
中的 MyChunkedUploadCompleteView
及其 on_completion
方法中看到。
def on_completion(self, uploaded_file, request):
# Do something with the uploaded file. E.g.:
# * Store the uploaded file on another model:
# SomeModel.objects.create(user=request.user, file=uploaded_file)
# * Pass it as an argument to a function:
# function_that_process_file(uploaded_file)
pass
在文档字符串中,您可以清楚地看到如何在模型中保存上传的文件。您需要编写自己的 on_completion
方法,例如
def on_completion(self, uploaded_file, request):
YourModelClass.objects.create(your_file_field=uploaded_file).save()
关于jquery - 有关 django-chunked-upload 和 jQuery-File-Upload 上传大文件的任何建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35193889/