AJAX-File-Uploader
Here is the link of the blog for this project, incase you want a code walk through.
Install django in your local machine if not installed.
pip install django
Run the project.
python manage.py runserver
This website collects cookies to deliver better user experience
{% load static %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
crossorigin="anonymous">
<title>AJAX + DJANGO File Uploader</title>
<link rel="stylesheet" href="{% static 'css/app.css' %}">
</head>
<body>
<div class="col-lg-6 col-md-6" style="margin: 100px auto; display: block;">
// drop zone
<div class="drop-box" id="dropBox" style="width: 100%; height: 400px; border: 4px dashed gray;" >
<p style="text-align: center; vertical-align: middle; line-height: 400px; font-size: 24px; color: gray;">Drag & Drop to Upload File</p>
</div>
<form enctype="multipart/form-data" method="POST" action="" style="text-align: center;">
<p style="color: gray; padding-top: 20px;">or</p>
{% csrf_token %}
<div class="form-group">
<label>Select file to upload.</label>
<input type="file" class="form-control" id="fileupload" placeholder="Select file">
</div>
<input type="submit" value="Upload" id="submit" class="btn btn-success">
</form>
<div id="uploaded_files"></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="{% static 'js/app.js' %}"></script>
</body>
</html>
...
ondragenter = function(evt) {
evt.preventDefault();
evt.stopPropagation();
};
ondragover = function(evt) {
evt.preventDefault();
evt.stopPropagation();
};
ondrop = function(evt) {
evt.preventDefault();
evt.stopPropagation();
const files = evt.originalEvent.dataTransfer;
var uploader = new FileUpload(files);
uploader.upload();
};
$('#dropBox')
.on('dragover', ondragover)
.on('dragenter', ondragenter)
.on('drop', ondrop);
Here is the link of the blog for this project, incase you want a code walk through.
pip install django
python manage.py runserver