Django-rest进度条上传 [英] Django-rest progress bar upload
问题描述
我有django模型与 FileField
和相关的django-rest序列化程序。我需要实现进度条上传。 django有默认解决方案,但是如何使用DRF执行?
I have django model with FileField
and related django-rest serializer. I need to implement progress bar upload. There is default solution for django, but how to perform it in terms of DRF?
UPD:问题是关于请求和视图。如何将 APIView
与 parser_classes =(MultiPartParser,FormParser,)
和 post
方法使用 request.META ['X-Progress-ID']
UPD: The problem is about requests and views. How to make APIView
with parser_classes = (MultiPartParser, FormParser,)
and post
method work with request.META['X-Progress-ID']
谢谢
Thanks
推荐答案
您应该使用javascript整合进度条。有很多js插件在那里创建进度条。例如,您可以使用 jQuery-File-Upload 。一个最小的例子可能是这样的(查看文档):
You should integrate the progress bar using javascript. There are many js plugins to create progress bars out there. For instance you could use jQuery-File-Upload. A minimal example could look like this (see docs):
$('#fileupload').fileupload({
/* ... */
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .bar').css(
'width',
progress + '%'
);
}
});
<div id="progress">
<div class="bar" style="width: 0%;"></div>
</div>
这篇关于Django-rest进度条上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!