Menu

Laravel 13 Drag and Drop File Upload with Dropzone.js and Vite
📰

Laravel 13 Drag and Drop File Upload with Dropzone.js and Vite

DEV Community: php·Muhammad Yasir Amin·3 days ago
#TDvn47Fk
#devto#dev#dropzone#file#uploads
Reading 0:00
15s threshold

Dropzone.js turns a box on your page into a drag and drop upload area with previews and progress bars. In Laravel 13 you install it with npm, load it through Vite, point it to a route that validates and stores each file, and send the CSRF token in a request header. This tutorial builds the whole flow for image uploads.

Targets: Laravel 13 (PHP 8.3 to 8.5), Vite and the dropzone npm package. Check the Dropzone documentation for any option changes in the version you install.

Step 1: Install Dropzone

npm install dropzone

Enter fullscreen mode

Exit fullscreen mode

Step 2: Import it in app.js

import Dropzone from 'dropzone' ; import 'dropzone/dist/dropzone.css' ;

Dropzone . autoDiscover = false ;

const element = document . getElementById ( 'image-dropzone' ) ;

if ( element ) { new Dropzone ( element , { url : element . dataset . url , paramName : 'file' , maxFilesize : 5 , acceptedFiles : 'image/jpeg,image/png,image/webp' , addRemoveLinks : true , headers : { 'X-CSRF-TOKEN' : document .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.