Dropzone.js only allows one audio file and one image thumbnail file to be uploaded simultaneously

Is there a way to limit the types of files that can be uploaded through Dropzone.js? Specifically, I want to restrict users to uploading only one image and one audio file.

Answer №1

To limit the maximum number of files, utilize the maxFiles parameter in your settings.

For additional customization, delve into the accept and/or events options.

Below is an untested code snippet that may assist you: (Unfortunately, testing on jsfiddle is not possible as the form action needs to be linked to a script for uploads. I'm curious about how they achieved their "upload-less" demo on the site).

// "myAwesomeDropzone" corresponds to the camelized version of the HTML element's ID
Dropzone.options.myAwesomeDropzone = {
    maxFiles: 2, // specify file limit
    acceptedFiles: "image/*,audio/*",
    accept: function (file, done) {
        if (new RegExp(file.type.split("/")[0]).test(this.getAcceptedFiles()[0].type)) {
            done("type already present");
        } else {
            done();
        }
    }
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on how to use Ajax in Flask to render a template after a post request

I'm looking to dynamically render a new template after making a jQuery ajax post request. Can someone provide guidance on how to achieve this using jQuery/ajax? Below is the initial route where the post request is sent: @app.route("/data") def data( ...

Is it possible for JavaScript to interact with elements that are created dynamically?

It's puzzling why the newly generated elements remain unseen by the next function that is called. Any insights on how to address this issue would be greatly appreciated! Resolve: Incorporate async: false to deactivate the asynchronous feature in order ...

Utilizing jQuery to toggle containers based on link clicks

Hello everyone, I'm having trouble getting this code to work. I have a set of 4 links and I need to display one div container for 3 of them, and another for the remaining 1 link, switching back and forth. Any suggestions? <div class="content activ ...

Strange behavior noticed in the app.get() method of Node.js Express

Seeking clarification regarding the behavior of app.get() in Express. It appears that the function is not triggered when the path includes .html at the end. In the code snippet provided, the console logs "test" if attempting to access /random/example, bu ...

How can I make TypeScript mimic the ability of JavaScript object wrappers to determine whether a primitive value has a particular "property"?

When using XMLValidator, the return value of .validate function can be either true or ValidationError, but this may not be entirely accurate (please refer to my update). The ValidationError object includes an err property. validate( xmlData: string, opti ...

Populate a dropdown with values from a JSON object

There is a function in my code that retrieves JSON text from a specific website: window.onload = function httpGet() { var xmlHttp = null; var box = document.getElementById("http") //just for testing xmlHttp = new XMLHttpRequest(); xmlHttp. ...

Render variable values with Mustache syntax

There are two separate html pages named home and about. Each page contains a js variable defined at the top of the page: var pageAlias = 'home'; // on the home page var pageAlias = 'about'; // on the about page The goal is to pass thi ...

Is the jQuery ajax .done() function being triggered prematurely?

Struggling with a problem here. I'm dealing with this code (simplified): var initializeZasilkovna = function () { // Initialize object window.packetery.initialize(); }; // Check if the object doesn't exist if (!window.packetery) { // It ...

Is there a way to retrieve JSON data from a specific URL and assign it to a constant variable in a React application?

I am exploring react-table and still getting the hang of using react. Currently, in the provided code snippet, a local JSON file (MOCK_DATA.json) is being passed into the const data. I want to swap out the local JSON with data fetched from a URL. How can ...

Changing images dynamically using Javascript when hovering over an element

Looking to create a dynamic image switch effect on hover, where multiple images cycle through when hovered over. Each time the mouse hovers over the image, it should switch to the next in a sequence of 5 images. <img id="switch" src="img1.jpg"> $(& ...

Delegating events after removing a class

I have a button element with the 'next' data attribute <button data-button='next' class="disabled">next</button> When I remove the disabled class to activate it, the click event doesn't trigger as expected $("[dat ...

uncertainty when implementing ng-if / ng-show / ng-hide

I am facing an issue with exporting content to PDF from my HTML. When a user clicks on the export button, the PDF is downloaded, but there are certain divs whose content I do not want to be exported or shown in the PDF. However, I still want them to be vis ...

Personalized service implemented in Angular's .config settings

I've come across a few examples of how to insert custom providers into angular's .config, but I'm struggling to do it correctly. Here's the provider I have: (function() { var app = angular.module('application.providers', [& ...

Using require to access an Immediately Invoked Function Expression variable from another file in Node.js

File 1 - Monitor.js var MONITOR = (function () { // Code for Monitoring return { doThing: function() { doThing(); } }; })(); File 2 - Test.js var monitor = require('../public/js/monitor.js'); I am trying to access the doThing() funct ...

The Controller is encountering an empty child array when attempting to JSON.stringify it

After examining numerous similar questions, I am uncertain about what sets my configuration apart. I've experimented with various ajax data variations and JSON formatting methods, but the current approach seems to be the closest match. This issue is ...

Issues with Ajax call not returning view in .NET MVC

I'm currently facing a specific issue with posting data to my MVC action in the controller using the following code: $(".btnAnalyze").click(function () { if (jQuery.isEmptyObject(product_ids) == true) { alert("Array is empty"); } ...

Top method for integrating configuration into a module

I'm trying to create a module called something.js that depends on a configuration, but I don't want the module itself to explicitly require the config. Additionally, I need my code editor to be able to analyze the module and provide autocomplete ...

Webpack-dev-middleware is serving the bundle on a port that is distinct from the application

Recently, I've been developing a React boilerplate that fully utilizes Apollo-Client and GraphQL. The setup of my application consists of one node process overseeing an Express server on port 3000 to render the app, and another Express server on port ...

The socket.on() function is not able to receive any data

I am encountering an issue with implementing socket.on functionality $('#showmsg').click(function() { var socket = io.connect('http://localhost:3000'); var msgText = $('#msgtext'); socket.emit('show msg', msgText.va ...

What could be causing the malfunction of removeEventListener in my Nuxt application?

Whenever a search result is displayed on my app, the component below renders and checks if the user scrolling is at the bottom of the page. Initially, the code works fine, but I encounter an error when returning to the page after navigating away and scro ...