I am trying to use Dropzone.js on my Laravel website.
This is my setup:
index.blade.php
:
<form action="/documents" method="POST" class="dropzone" id="my-dropzone" enctype="multipart/form-data">
@csrf
</form>
And in my app.js
file, I have below code:
window.Dropzone = require('dropzone');
(function () {
Dropzone.autoDiscover = false;
Dropzone.options.myDropzone = {
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 1, // MB
acceptedFiles: 'image/*,application/pdf',
parallelUploads: 8,
addRemoveLinks: false,
createImageThumbnails: false,
autoProcessQueue: true,
previewTemplate: document.getElementById('dropzone-preview-template').innerHTML,
accept: function (file, done) {
console.log(file.name)
},
};
});
The actual Dropzone element is appearing on the page, and I can use it to upload files. However, my Dropzone.options
are not being respected.
For example, I can upload files larger than 1MB, I can upload all file types, even though I only want to be able to upload images and PDF files.
If I move this: Dropzone.autoDiscover = false;
outside the (function () {});
, the Dropzone element don't work at all.
What do I do wrong?