I would like to be able to drag from my web application onto another web application which expects a WAV file. I don't have any control over the target application.
I can create the bytes of the WAV file, but the files property of the data transfer event is read only, so I don't see a way to add the file there. My makeWav function returns a DataView of the binary data.
My code here fails because "files" is read only.
this.div.addEventListener('dragstart', (ev: DragEvent) => {
const data = WavMaker.makeWav(
this.audioCtx, this.buffer, this.startOffsetS, this.durationS);
const f = new File([data.buffer], "clip.wav");
ev.dataTransfer.files = [f]; // Fails because 'files' is read only.
ev.dataTransfer.effectAllowed = "copy";
});
Maybe there is some way to do this with the setData function, but this uses a string for the data, not a binary object:
const stringData = String.fromCharCode(...new Uint8Array(data.buffer));
ev.dataTransfer.setData("audio/webm", stringData);
When I do this, I get the expected green "+" when I drag the element onto the target page, but the target application does nothing in response after dropping the element. It is probably just eating the error and not logging anything to the console.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment