react-csv-reader icon indicating copy to clipboard operation
react-csv-reader copied to clipboard

is it possible to run onFileLoaded when I am manually adding the file using drop event

Open rahgurung opened this issue 3 years ago • 0 comments

I am manually adding the file using Drag and Drop API, on the drop I am pointing the file to the input field but this doesn't trigger the onFileLoaded. Code sample (this isn't the real react code) to manually adding the file using drop event:

function handleDroppedFile(evt) {
  evt.preventDefault();
  // since we use jQuery we need to grab the originalEvent
  var dT = evt.originalEvent.dataTransfer;
  var files = dT.files;
  if (files && files.length) {
    // we set our input's 'files' property
    $('#image-event')[0].files = files;
  }
}
$('#image-event-label').on({
    'drop': handleDroppedFile
  })

<label for="image-event" id="image-event-label">
        Drop a file here
</label>
<input type="file" name="image-event" id="image-event">

rahgurung avatar Mar 10 '21 17:03 rahgurung