Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dropzone

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dropzone

Handles drag and drop of files for you.

  • 6.0.0-beta.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
533K
increased by6.55%
Maintainers
1
Weekly downloads
 
Created

What is dropzone?

Dropzone is a JavaScript library that provides drag-and-drop file uploads with image previews. It is highly customizable and easy to integrate into web applications.

What are dropzone's main functionalities?

Basic File Upload

This code demonstrates how to create a basic Dropzone instance for file uploads. It specifies the URL to which files will be uploaded, the parameter name for the file, the maximum file size, and the accepted file types.


const Dropzone = require('dropzone');

// Create a Dropzone instance
const myDropzone = new Dropzone('#my-dropzone', {
  url: '/file/post',
  paramName: 'file',
  maxFilesize: 2, // MB
  acceptedFiles: '.jpeg,.jpg,.png,.gif'
});

Custom Preview Template

This code demonstrates how to create a Dropzone instance with a custom preview template. The template defines the HTML structure for the file preview, including elements for the thumbnail, file name, file size, progress bar, and error/success messages.


const Dropzone = require('dropzone');

// Custom preview template
const previewTemplate = `
  <div class="dz-preview dz-file-preview">
    <div class="dz-image"><img data-dz-thumbnail /></div>
    <div class="dz-details">
      <div class="dz-size"><span data-dz-size></span></div>
      <div class="dz-filename"><span data-dz-name></span></div>
    </div>
    <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>
    <div class="dz-error-message"><span data-dz-errormessage></span></div>
    <div class="dz-success-mark"><span>✔</span></div>
    <div class="dz-error-mark"><span>✘</span></div>
  </div>
`;

// Create a Dropzone instance with custom preview template
const myDropzone = new Dropzone('#my-dropzone', {
  url: '/file/post',
  previewTemplate: previewTemplate
});

Event Handling

This code demonstrates how to handle various events in Dropzone. It shows how to log messages when a file is added, track the upload progress, and handle successful uploads.


const Dropzone = require('dropzone');

// Create a Dropzone instance
const myDropzone = new Dropzone('#my-dropzone', {
  url: '/file/post'
});

// Event handling
myDropzone.on('addedfile', function(file) {
  console.log('File added:', file.name);
});

myDropzone.on('uploadprogress', function(file, progress) {
  console.log('Upload progress:', progress);
});

myDropzone.on('success', function(file, response) {
  console.log('File uploaded successfully:', response);
});

Other packages similar to dropzone

Keywords

FAQs

Package last updated on 29 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc