I have a FBX file generated from blender which I'm trying to pack with a zip for use in an application that uses THREE JS to render images in an AR environment for use in a Webapp. Right now I'm trying to upload it using javascript however the data of the result is always corrupted by a few bytes, rendering it completely useless. I am using HexFiend on MacOS 10.13.6 to inspect the files.
The file is a 1x1x1 cube in Blender which was exported using the 7.3 FBX Binary protocol. This is then loaded in from a Vue.js client to a Laravel / Php 7.0.31 backend. Don't mind the indentation for now - this is my latest attempt.
var decoder = new TextDecoder('utf-8');
var reader = new FileReader();
reader.onload = (e) => {
let asset = {};
var result = new Uint8Array(e.target.result);
var array = decoder.decode(result);
asset.data = array;
asset.filename = file.name;
asset.size = file.size;
asset.mime = file.type != '' ? file.type : "application/octet-stream";
console.log(asset.data);
//save it to an object that is then posted to the php side.
}
reader.readAsArrayBuffer(file);
The files are generated, but always off by a few bits causing them to corrupt and become utterly useless. I need to keep the binary of the file as pure as possible. My suspicion is that the utf-8 encoding breaks it by transforming a few characters.
So far I have tried the following:
- readAsBinaryString: this resulted in equal artifacts and rendered the file useless after processing.
- readAsText: this, unsurprisingly, results in the same result as above.
- readAsDataURL: this creates an unknown mime type for the base64 instance which can't be used on the front end so is out of the question.
- readAsArrayBuffer injected directly into the object: Unfortunately is just a giant array of unorganized numbers
- Inject ',' or '.' between the arraybuffer to then 'decrypt' before being usable. Inflated the size by 2,5 times and didn't work! So not a good solution.
- cast the array to 16bit - again, would need to be 'decrypted' before being usable. So out of the question.
- Use String.fromCharCode.apply(null, array) to make the array. Results in similar as the above situation.
So far the only significant change I have seen is between readAsBinaryString and the above solution. But both are not correct.