Uploading Images – ASPNET Core and DropzoneJS
April 25, 2016 by Anuraj
C# ASPNET5 ASPNET Core DropzoneJS Drag and Drop
DropzoneJS is an open source library that provides drag and drop file uploads with image previews. It is lightweight, does not depend on any other library (like jQuery) and is highly customizable. This post is about implementing Upload images with drag and drop feature in ASP.NET Core and DropzoneJS.
You can download DropzoneJS from github.
Once you download, add reference of CSS and Script file in your MVC layout page or to the required page, where you need Drag and Drop feature.
Here is the HTML code.
The DIV with fallback class will be displayed, if users browser doesn’t support drag and drop. Here is the script, which handles the client side configuration.
UploadForm is the Form Id. Here I am configuring options like, restrict the file size to 20 MB and only allow image files. You can find more configuration options in DropzoneJS web site. Here is the server side code, which receives the files and save in the server location.
Unfortunely the IFormFile option is not working, so I had to change to HttpContext.Request.Form.Files instead of IFormFile collection to read the uploaded files from client. If you are using IFormFile as part of model it is working. Only IFormFile collection is not working.
Here is the application running on my system.
Happy Programming :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub