[SOLVED] File.size on the glB-file loading

I am in doubt if this is correct? (have already been looking at:

So trying:

        app.assets.loadFromUrlAndFilename(self.url, null, "container", function (err, asset) {
        console.log("FileSize: "+ asset.file.size);
            // Add the loaded scene to the hierarchy
            self.entity.addComponent('model', {
                asset: asset.resource.model,  
                material: self.app.assets.get(30625063).resource
            });
  • where the output is ‘FileSize: undefined’.

Going a bit further:

        app.assets.loadFromUrlAndFilename(self.url, null, "container", function (err, asset) {
           // Add the loaded scene to the hierarchy
            self.entity.addComponent('model', {
                asset: asset.resource.model,  
                material: self.app.assets.get(30625063).resource,
                file: file.size
            }); 
            console.log("FileSize: "+ file.size);
  • which fails (even before webupload :-/ )

Looking at the engine code, the properties on the file object are not guaranteed. It’s extra meta data that needs to be explicitly set. My guess is that for Editor projects, this data is given but for files from loadFromUrlAndFilename, you can see from the engine code that it only contains the URL and filename: https://github.com/playcanvas/engine/blob/master/src/asset/asset-registry.js#L480

Added issue to updated documentation: https://github.com/playcanvas/engine/issues/2214

As far as I know, there isn’t a way to get the file size of the asset that you have downloaded.

Your best bet is to get the size of file via XHR (e.g. https://bitexperts.com/Question/Detail/3316/determine-file-size-in-javascript-without-downloading-a-file)

The asset object is meant to hold the meta data about the resource type it represents so it only holds the data that the developer gives (the URL, filename, type etc) and then it loads the resource based on that data.

Ok sounds like a thorough explanation … I have a backup plan but worth the try with this otherwise 1st priority