danielm / uploader

A lightweight and very configurable jQuery plugin for file uploading using ajax(a sync); includes support for queues, progress tracking and drag and drop.
https://danielmg.org/demo/java-script/uploader
MIT License
1.17k stars 384 forks source link

How to read file uploaded in Drag & Drop #102

Open leorcdias opened 5 years ago

leorcdias commented 5 years ago

I am trying to read an XLSX file when uploading in the "Drag & Drop" field. How can I do this without using jQuery's change function?

My project is part of a college assignment, which I am due to deliver this Saturday, and I have problems with that part :(

Library used to read XLSX: SheetJS

My JS Code:

function uploadedXLSX(e) { let reader = new FileReader(); reader.readAsBinaryString(e.target.files[0]) reader.onload = (e) => { let data = e.target.result; let workbook = XLSX.read(data,{type: 'binary'}); let first_sheet_name = workbook.SheetNames[0]; let worksheet = workbook.Sheets[first_sheet_name]; let jsonObj = XLSX.utils.sheet_to_json(worksheet,{raw: false}); return orderData(jsonObj) } }

$(document).ready(function () { $('#fileUploader').change(function (e) { uploadedXLSX(e); }); });

dmUploader Config:

url: 'backend/upload.php', maxFileSize: 5000000, // 5 Megs, extFilter: ["xls", "xlsx"], multiple: false