I want to prevent a duplicate file to be uploaded from dropzone My dropzone takes only two files so I want to check if the second file has the same filename as the first one if so change the second filename
using the renameFile function
I have added a if statement that checks if the file content are equal the if statement gets not executed if the condition is true
using a simple version the file gets renamed when send to the server but gets not renamed inside dropzone
renameFile: function (file) {
let filename = file.name = "sdsdds.xlsx";
return filename;
renameFile: function (file) {
let name = file.name
let div_children = $('.dz-filename').children();
// get filename of already existing file
if (div_children.eq(0).text() !== ""){
if (div_children.eq(0).text() === div_children.eq(1).text() ) {
console.log(file.name)
let filename = file.name = "sdsdds"
return filename;
}
}
},
document.addEventListener("DOMContentLoaded", function() {
Dropzone.options.dropform = {
maxFiles: 2,
addRemoveLinks: true,
maxFilesize: 2,
parallelUploads: 1, //
renameFile: function(file) {
let name = file.upload.filename
let div_children = $('.dz-filename').children();
// get filename of already existing file
if (div_children.eq(0).text() !== "") {
if (div_children.eq(0).text() === div_children.eq(1).text()) {
console.log(name)
return name = "sdsdds"
}
}
//
},
};
});
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.1/min/dropzone.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.2/min/dropzone.min.js"></script>
</head>
<body>
<form id="dropform" action="{{ url_for('receave_files') }}" class="dropzone">
</form>
</body>
</html>