Python Django AngularJs dropzone 多个上传文件 爬坑

来源:互联网 发布:艾米莉狄金森 知乎 编辑:程序博客网 时间:2024/05/16 13:45

最近 使用了 dropzone 的 多个 文件 上传的功能 ,参考网站上的说明并没有很快实现,并且网站的后台是 使用 Java 写的,我需要使用的python ,所以总结教程中的几个 问题:

1.dropzone.js 下载地址
2.dropzone 参考网站地址

3.出现的问题 :
3.1 报错信息 :$scope.processQueue is not a function
解决方式:$scope.processQueue();函数 写错了,应该是processDropzone 可以在后面对应的函数发现 processDropzone是 调用了 processQueue()函数 所以肯定是名称写错了

/* js/fileAppControllers.js */            ...            fileAppControllers.controller('FileCtrl', ['scope',                function ($scope) {                    $scope.partialDownloadLink = 'http://localhost:8080/download?filename=';                    $scope.filename = '';                    $scope.uploadFile = function() {                        $scope.processQueue();                    };                    $scope.reset = function() {                        $scope.resetDropzone();                    };                }            ]);

3.2 报错情况:demo中是可以实现多个文件上传的,但是把网站上js复制下来,发现最后只能是上传最后一个
原因是 : js 文件中多加个函数:if 函数中表示如果上传的第二个文件存在files[1]!=null就会删除之前所有的文件,只剩下最后一个!
解决方式:删除If语句既可以

var eventHandlers = { 'addedfile': function(file) {    scope.file = file;     if (this.files[1]!=null) {     this.removeFile(this.files[0]);     } scope.$apply(function() {    scope.fileAdded = true;                 );    },'success': function (file, response) {   }                             };

3.4 js 中 dropzone 报错信息 :dropzone is undefined
原因是 在 js 中 定义一个 新的变量 dropzone 前面需要加上 var
解决方式 :var dropzone = new Dropzone(element[0], config);
ps :这个问题 我查出来花了三个小时,新手爬坑真的是好惨

3.5 报错情况:ontroller 'carousel', required by directive 'ngTransclude', can't be found
原因是 : 未知 还需要回来补充这一段

3.6 后台python实现:
报错情况:the server responded with a status of 405 (Method Not Allowed)表示使用的方法是不正确的,DropZone 默认使用的post的方式传数据
解决方式是后台使用post接收,我用的是Viewset中的 APIView,本来我用的是 get方法,后来改成了 post,因为是 多个文件上传所以request.FILES.iteritems():类型是 dict,需要使用 循环得到每一个 文件,代码如下

class PropertyUploadFileInteractiveView(APIView):    def post(self, request, *args, **kw):        property_id = request.GET['property_id']        for key, value in request.FILES.iteritems():返回的是response              op_result = 'success'                    result ={'result':op_result}                    response = Response(result, status=status.HTTP_200_OK)                    #return response                    #return HttpResponseRedirect("/ui-property/property_detail/%s" % property_id)                 else:                    op_result = 'fail'                    result ={'result':op_result}                    response = Response(result, status=status.HTTP_200_OK)            。。。。。

中文版config的参考