Skip to content

Instantly share code, notes, and snippets.

@MSakamaki
Last active August 29, 2015 14:21
Show Gist options
  • Save MSakamaki/3342600859e14e975405 to your computer and use it in GitHub Desktop.
Save MSakamaki/3342600859e14e975405 to your computer and use it in GitHub Desktop.
テスト用コード@ドラッグ&ドロップのファイル版 Drag And Drop Api for File
var ary_u8 = new Uint8Array([0x30,0x82,0x06,....]); // byte code
var file = new File([ary_u8], 'file name', {
lastModified: new Date(0),
type: "application/json"
});
var dispatchDrop = function(ary_u8){
var createEvent= function(type) {
var event = document.createEvent("CustomEvent");
event.initCustomEvent(type, true, true, null);
event.dataTransfer = {
files: [ ary_u8 ]
};
return event;
}
var type = 'drop';
var elm = document.querySelector('.upload-drop-zone');
var event = createEvent( type );
elm.dispatchEvent( event );
}
dispatchDrop(file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment