这是我的代码。它会添加到数据库中,但不会上传到该文件夹。我不知道在哪里放置文件应该上传的文件路径,我不知道如何检索文件的文件名,以便我可以将其添加到数据库中。上传到数据库的唯一内容是ObjectId,它由MongoDB自动提供。
的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 :(得分:0)
修正:我在金字塔的文档中跟踪了文件上传