2017-05-05 94 views
0

這是我的代碼。它添加到數據庫中,但不會上傳到該文件夾​​。我不知道在哪裏放置路徑文件夾名,其中文件應該上傳,我不知道如何檢索文件的文件名,所以我可以將它添加到數據庫。上傳到數據庫的唯一東西是由MongoDB自動提供的ObjectId。使用Dropzone進行文件上傳,但沒有上傳到文件夾

的Javascript

window.onload = function() { 
Dropzone.options.myAwesomeDropzone = { 
     paramName: "file", 
     maxFilesize: 10, 
     url: 'UploadImages', 
     previewsContainer: "#dropzone-previews", 
     uploadMultiple: true, 
     parallelUploads: 5, 
     maxFiles: 20, 
     init: function() { 
      var cd; 
      this.on("success", function(file, response) { 
       $('.dz-progress').hide(); 
       $('.dz-size').hide(); 
       $('.dz-error-mark').hide(); 
       console.log(response); 
       console.log(file); 
       cd = response; 
      }); 
      this.on("addedfile", function(file) { 
       var removeButton = Dropzone.createElement("<a href=\"#\">Remove file</a>"); 
       var _this = this; 
       removeButton.addEventListener("click", function(e) { 
        e.preventDefault(); 
        e.stopPropagation(); 
        _this.removeFile(file); 
        var name = "largeFileName=" + cd.pi.largePicPath + "&smallFileName=" + cd.pi.smallPicPath; 
        $.ajax({ 
         type: 'POST', 
         url: 'DeleteImage', 
         data: name, 
         dataType: 'json' 
        }); 
       }); 
       file.previewElement.appendChild(removeButton); 
      }); 
     } 
    }; 
}; 

HTML

<form action="UploadImages" class="dropzone" id="my-awesome-dropzone" enctype="multipart/form-data"> 
</form> 

的Python

@view_config(route_name='upload', request_method='POST', renderer='json') 
    def upload(self): 
     # Only allow post data 
     if self.request.method != 'POST': 
      return {'success' : False, 'error' : True, 'message' : 'Post method is only allow'}   
     user = Dropzone(
      firstname = self.request.POST.get('firstname')) 
     user.save() 

     return ['sample'] 
+0

固定:我在金字塔的文檔中使用了文件上傳 – sbrnavls

回答

0

修正:我跟着文件上傳在金字塔的文檔中

相關問題