It looks like you've started creating an HTML document that utilizes the Dropzone library for file uploads. Below, I will provide a complete example that includes a functional Dropzone area and the necessary styles to get you started.
Here's a full example, including both the HTML structure and CSS styles for a file transfer download feature:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Transfer Download with Storage</title>
<script src="https://unpkg.com/dropzone@6.0.0-beta.1/dist/dropzone-min.js"></script>
<link href="https://unpkg.com/dropzone@6.0.0-beta.1/dist/dropzone.css" rel="stylesheet" type="text/css" />
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
}
.dropzone {
border: 2px dashed #007bff;
background: white;
padding: 20px;
margin: auto;
width: 80%;
max-width: 600px;
border-radius: 5px;
transition: border-color 0.3s, background 0.3s;
}
.dropzone:hover {
border-color: #0056b3;
background: #e9f7ff;
}
.dz-message {
text-align: center;
padding: 20px;
}
.dz-preview .dz-image img {
width: 100px;
height: 100px;
object-fit: cover;
}
.file-list {
margin-top: 20px;
list-style: none;
padding: 0;
}
.file-list li {
padding: 10px;
background: #fff;
border: 1px solid #ddd;
margin-bottom: 10px;
border-radius: 5px;
}
</style>
</head>
<body>
<h1>Upload Your Files</h1>
<form action="/upload" class="dropzone" id="myDropzone"></form>
<h2>Uploaded Files</h2>
<ul class="file-list" id="fileList"></ul>
<script>
Dropzone.options.myDropzone = {
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 2, // MB
acceptedFiles: ".jpg,.jpeg,.png,.gif,.pdf",
success: function (file, response) {
// Add the uploaded file to the list
let fileList = document.getElementById('fileList');
let li = document.createElement('li');
li.textContent = file.name;
fileList.appendChild(li);
},
error: function (file, response) {
console.error('Upload failed:', response);
}
};
</script>
</body>
</html>
Explanation:
-
HTML Structure: The document includes a <form> element where Dropzone will manage file uploads. There's also a section to display the list of uploaded files.
-
CSS Styles: Basic styles are applied to make the Dropzone visually appealing and user-friendly.
-
JavaScript Configuration: The Dropzone is configured with options such as:
paramName: Specifies the name attribute of the form data.
maxFilesize: Sets the maximum file size (in MB).
acceptedFiles: Limits the upload to certain file types.
success function: This function executes when a file is successfully uploaded, adding the file name to the list of uploaded files.
error function: Handles any errors that occur during the upload process.
Note:
- Make sure to replace the
action attribute in the <form> tag (/upload) with the correct endpoint on your server that handles the file upload.
- The uploaded files are displayed in a list right below the Dropzone, providing user feedback.
You can further enhance this example by adding functionality to actually handle file storage on the backend server as needed.