Search code examples
javascripthtmlflashecmascript-6

Using a Blob as a Flash object


I am trying to use a Flash object stored in a blob, however my approach using the URL returned by URL.createObjectURL as the src of the embed tag just results in the browser downloading the blob as a file.

Here's my generated HTML:

<object height="500" width="1000">
    <embed height="500" width="1000" src="blob:http://127.0.0.1:34721/1fa7a01c-25b7-4ad0-ba1d-1ddef61617ce"/>
</object>

And here's JavaScript used to generate the Blob and object tag:

var blob = new Blob(data, {
               type: 'application/x-shockwave-flash'
           });

document.body.innerHTML += '<object height="500" width="1000" ><embed height="500" width="1000" src="' + URL.createObjectURL(blob) + '"/></object>'

Where data is an array of Uint8Arrays, each containing 256 bytes of the binary data.

The blob in question has a type of application/x-shockwave-flash and is identical to the original .swf file (I checked). The file itself works when used in place of the Object URL.

From what I have read, an Object URL pointing to a blob can be used any place a normal URL could. Are embed tags an exception to this?


Solution

  • The embed tag may miss the mime type that it normally gets from a response header. Try setting "type="application/x-shockwave-flash" as an attribute inside your embed tag.

    Still, Flash isn't widely supported anymore, I'd test across browsers to see if it's the same error. You may need to add the type to the object tag in legacy browsers.