omrips / viewstl

Viewstl Javascript plugin - STL/OBJ 3D files Viewer by viewstl.com
MIT License
186 stars 46 forks source link

Blob File Support In IE11 #4

Closed lefevre-fraser closed 3 years ago

lefevre-fraser commented 3 years ago

Scenario: I have an R server running, and it has access to files that are not in the webroot. I don't want to copy the files into the webroot in order to load them via URL, just to delete them a second later. In browsers other than IE11 I can use the File 'class' function to create a valid file object: new File([(new Int8Array(array_of_bytes)).buffer], "File.stl");

In IE11 however, the File 'class' function does not exist. I'm trying to use a Blob object in place of the File object since a File object is a variation of the Blob object. The issue I encounter when passing a Blob object is that it is missing the 'name' property that is used in parse_3d_file function from the "parser.min.js" file has the function split called on it for obtaining the file type via file extension, and then throws an error because the 'name' property does not exist.

I have tried adding the 'name' property to the Blob object, but as soon as it is passed through the postMessage function any non-standard Blob properties are lost. In order to handle the issue, I propose a simple solution: If the name property is undefined on the local_file object, then use the filename property that would usually define a URL to provide the file name.

Possible Solution: The following line could be modified in this manner: This: https://github.com/omrips/viewstl/blob/a8d0fb71e71f5ce4c237ca7cb6cdb54cadea4d7d/src/load_stl.js#L31 Would becomes this: filename=e.data.data.local_file.name?e.data.data.local_file.name:e.data.data.filename;

If you need any further information regarding this issue please let me know.

Thank you, Fraser

omrips commented 3 years ago

Thanks Fraser,

Good call, fix uploaded.

lefevre-fraser commented 3 years ago

Thank you for fixing that so quickly.