You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Dropzone设置acceptedFiles限制上传文件类型失效求助

Fixing Dropzone acceptedFiles Not Taking Effect

It looks like the core issue is how you're targeting your Dropzone forms in the configuration script. Let's break this down and get it sorted out quickly.

The Root Cause

Your two upload forms have IDs mainDiv and recommendationDiv, but your script is trying to apply settings to a Dropzone instance with the ID dropzone—which doesn't exist in your HTML. Dropzone links configuration options to form IDs using the pattern Dropzone.options.[formId], so your current code isn't attaching the file type rules to either of your actual upload forms.

Solution 1: Configure Each Form Individually

If you want to keep using Dropzone's automatic initialization (it auto-initializes elements with the dropzone class), update your script to target each form's specific ID:

// Configure the first upload form (id="mainDiv")
Dropzone.options.mainDiv = {
  acceptedFiles: 'image/*'
};

// Configure the second upload form (id="recommendationDiv")
Dropzone.options.recommendationDiv = {
  acceptedFiles: 'image/*'
};

Solution 2: Unified Initialization (Cleaner for Identical Rules)

Since both forms share the same file type restriction, you can manually initialize all dropzone class forms with a single shared configuration to avoid repeating code:

// Initialize all forms with the "dropzone" class
document.querySelectorAll('.dropzone').forEach(formElement => {
  new Dropzone(formElement, {
    acceptedFiles: 'image/*'
  });
});

Small Bonus Tip

I noticed your prompt text has duplicate "PDF" entries—you might want to clean that up for better clarity:

(Please upload PDF, JPG, GIF, PNG files only.)

内容的提问来源于stack exchange,提问作者Muhammad Umar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:10:22