in js i'm running this code
let str = new TextDecoder("utf8").decode(new Uint8Array(reader.result));
let data = {
name:file.name,
size: args.loaded,
contentsize:str.length,
type:file.type,
content:str
};
let res = await $.post({
url:"/api/files",
data:JSON.stringify(data),
processData: false,
contentType: "application/json",
})
reader.result is the output of
reader.readAsArrayBuffer(file);
which is then being picked up in php
$new["actual"] =strlen($new["content"]);
$new["content"] = new MongoDB\BSON\Binary($new["content"] ,MongoDB\BSON\Binary::TYPE_GENERIC);
$result = IO::$db->files->insertOne($new);
which then results in a db document of
{
"name" : "test.pdf",
"size" : NumberInt(128454),
"contentsize" : NumberInt(122693),
"type" : "application/pdf",
"actual" : NumberInt(215693)
}
however when i remove the content of the file back to the file system the file is corrupted and wont open. i've run the file comparer that comes with VSCode over it and says there are 0 differences between the DB content and the original, so i can only think the issues is with the 3kb difference in the file size and the read content, but what or why escapes me
note only seems to be Binary files