I'm trying to make it so a user can drag an icon from the web browser to their desktop, and a text file is created. I've got the content part down, but I can't figure out how to set the filename. I've tried mutating dataTransfer.files
but that's read-only. I'm not sure how to achieve this.
class CrashReport extends React.Component {
dragStart(event) {
const dat = {name: 'test!', crashDate: new Date()};
event.dataTransfer.name = 'tmp.txt'; // bad
event.dataTransfer.setData('text/plain', JSON.stringify(dat, null, 2));
console.log(event.dataTransfer);
}
render() {
return <div draggable onDragStart={this.dragStart.bind(this)}>
Drag This
</div>
}
}