Uploading GLTF File Error

I am having some trouble uploading GLTF files into kirby. I’m trying to make a three.js viewer.
When I try to upload into the files field, I get the error messaage
“The media type for “xxxx.gltf” cannot be detected”
image

I’ve made sure all file types are accepted in the file blueprint but it doesn’t seem to be changing anything.

I suspect this file type is not supported.

… but there is a workaround, right?

You could upload these files via the file system instead of via the Panel.

Kirby 3.6 will support custom file types.

1 Like

Shouldn’t it work already? I use accept: true, but it still throws an error with Invalid file type: -for .gltf files.

You can register custom file types that are not supported natively by Kirby since 3.6:

1 Like

Like this?

<?php
Kirby::plugin('napoleon/gltf', [
  'fileTypes' => [
    'gltf' => [
      'mime' => 'model/gltf',
      'type' => 'gltf',
    ],
  ]
]);

Guess you are asking because it doesn’t work? You probably have to use one of Kirbys existing file types (document, image, video, archive, audio, code) or add new filetypes. If you use image, for example, it will upload.

Hello, I just want to follow up on this since I have not been able to upload 3d files as well.
I am also trying to create a file section to upload GLB/ GLTF files via the panel.
After trying to register a new GLB file type, I still get an error “Call to a member function template() on null” with a failed upload.

This is after I tried

  'fileTypes' => [
      'glb' => [
        'mime' => 'images/png',
        'type' => 'images',
      ],

as well as

  'fileTypes' => [
      'glb' => [
        'mime' => ' model/gltf-binary',
        'type' => 'model',

Any suggestions are welcome, thank you!

type can be audio, code, document, image and video (see Kirby file types). For the mime attribute, you can explore a list of common MIME types.

So gltf, model or images are not valid types.

Thank you for your reply! However this still returns the same error “Call to a member function template() on null”

  'fileTypes' => [
      'glb' => [
        'mime' => ' image/png',
        'type' => 'image',

Also, I just tried this with audio/aac to test a different file format and got the same result

  'fileTypes' => [
      'glb' => [
        'mime' => ' audio/aac',
        'type' => 'audio',

Is there more information in the console or in your PHP error logs?

Just this :

XHRPOSThttp://localhost/apm/api/pages/threed+model1/files
[HTTP/1.1 500 Internal Server Error 296ms]

Hm, I just tested it in my environment with the following settings:

  1. Files section in blueprint
  files:
    type: files
    template: glb
  1. Files blueprint site/blueprints/files/glb.yml
title: glb

accept:
  extension: glb
  1. Plugin with fileTypes extension

index.php

<?php

Kirby::plugin('texnixe/uploads', [
    'fileTypes' => [
        'glb' => [
          'mime' => ' model/gltf-binary',
          'type' => 'image',
        ]
    ]
]);

glb test file downloaded from here: glTF-Sample-Models/2CylinderEngine.glb at master · KhronosGroup/glTF-Sample-Models · GitHub

Mime type: Media Types

1 Like

Works perfectly, thank you so much!

I did all of the above, and it worked indeed. Thanks!
Now I try to integrate the url of the model in the page.

I tried:

$src = $page->file()->url();
$src = $block->model()->toFile()->url();

The first one gave met the url I need, but I need to have more models one one page,
so I can’t really use it this way. The second one throws an error. ‘Array to string conversion’.

So I guess my question is:
How do I get the url of the model from a files field into the page? (in this case ''model())

Thanks again!

What is model() in this example? The name of your files field inside the block?

Exactly!

The error is weird, though, does it really come from this line?

$src = $block->model()->toFile()->url();

On a side note, you should never call the url() method without making sure you have a file, but that doesn’t seem to be the issue here.

Maybe post the surrounding code as well…

Probably not all relevant, but this is the code:

plugin

<?php

Kirby::plugin('jv/uploads', [
    'fileTypes' => [
        'gltf' => [
          'mime' => ' model/gltf-binary',
          'type' => 'image',
        ]
    ]
]);

blueprints/blocks/modelviewer.yml

  model:
    label: Upload Model
    type: files
    max: 1
    width: 1/2
    multiple: false
    image:
      back: black
    uploads:
      template: files/3dmodel

blueprints/files/3dmodel.yml


accept:
  extension: gltf

blocks/modelviewer.php

<?php 
// Modelviewer Block

$src = $page->file()->url();
$src = $block->model()->toFile()->url();
?>

<model-viewer 
    ar
    autoplay
    src="<?= $src ?>" 
    shadow-intensity=".3" 
    camera-controls 
    touch-action="pan-y">
</model-viewer>

and the error:


Whoops\Exception\ErrorException thrown with message "Array to string conversion"

Stacktrace:
#48 Whoops\Exception\ErrorException in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Cms/Field.php:226
#47 Whoops\Run:handleError in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Cms/Field.php:226
#46 Kirby\Cms\Field:toString in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Cms/Field.php:126
#45 Kirby\Cms\Field:__toString in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/site/snippets/blocks/modelviewer.php:11
#44 include in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:425
#43 Kirby\Filesystem\F:loadIsolated in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:364
#42 Kirby\Filesystem\F:Kirby\Filesystem\{closure} in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:372
#41 Kirby\Filesystem\F:load in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Toolkit/Tpl.php:34
#40 Kirby\Toolkit\Tpl:load in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Template/Snippet.php:170
#39 Kirby\Template\Snippet:factory in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/config/components.php:284
#38 Kirby\Cms\Core:{closure} in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Cms/App.php:1628
#37 Kirby\Cms\App:snippet in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/config/helpers.php:597
#36 snippet in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/site/snippets/content/content_layout.php:104
#35 include in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:425
#34 Kirby\Filesystem\F:loadIsolated in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:364
#33 Kirby\Filesystem\F:Kirby\Filesystem\{closure} in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:372
#32 Kirby\Filesystem\F:load in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Toolkit/Tpl.php:34
#31 Kirby\Toolkit\Tpl:load in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Template/Snippet.php:170
#30 Kirby\Template\Snippet:factory in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/config/components.php:284
#29 Kirby\Cms\Core:{closure} in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Cms/App.php:1628
#28 Kirby\Cms\App:snippet in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/config/helpers.php:597
#27 snippet in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/site/snippets/content/content_basic.php:4
#26 include in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:425
#25 Kirby\Filesystem\F:loadIsolated in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:364
#24 Kirby\Filesystem\F:Kirby\Filesystem\{closure} in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:372
#23 Kirby\Filesystem\F:load in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Toolkit/Tpl.php:34
#22 Kirby\Toolkit\Tpl:load in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Template/Snippet.php:170
#21 Kirby\Template\Snippet:factory in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/config/components.php:284
#20 Kirby\Cms\Core:{closure} in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Cms/App.php:1628
#19 Kirby\Cms\App:snippet in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/config/helpers.php:597
#18 snippet in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/site/snippets/page/page_basic.php:115
#17 include in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:425
#16 Kirby\Filesystem\F:loadIsolated in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:364
#15 Kirby\Filesystem\F:Kirby\Filesystem\{closure} in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:372
#14 Kirby\Filesystem\F:load in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Toolkit/Tpl.php:34
#13 Kirby\Toolkit\Tpl:load in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Template/Snippet.php:170
#12 Kirby\Template\Snippet:factory in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/config/components.php:284
#11 Kirby\Cms\Core:{closure} in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Cms/App.php:1628
#10 Kirby\Cms\App:snippet in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/config/helpers.php:597
#9 snippet in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/site/templates/home.php:1
#8 include in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:425
#7 Kirby\Filesystem\F:loadIsolated in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:364
#6 Kirby\Filesystem\F:Kirby\Filesystem\{closure} in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Filesystem/F.php:372
#5 Kirby\Filesystem\F:load in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Toolkit/Tpl.php:34
#4 Kirby\Toolkit\Tpl:load in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Template/Template.php:155
#3 Kirby\Template\Template:render in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Cms/Page.php:1071
#2 Kirby\Cms\Page:render in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Cms/App.php:804
#1 Kirby\Cms\App:io in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/kirby/src/Cms/App.php:1243
#0 Kirby\Cms\App:render in /customers/b/4/7/johannesverwoerd.nl/httpd.www/clients/typeinspace/index.php:5

   }
 
    /**
     * Converts the Field object to an array
     *
     * @return array
     */
    public function toArray(): array
    {
        return [$this->key => $this->value];
    }
 
    /**
     * Returns the field value as string
     *
     * @return string
     */
    public function toString(): string
    {
        return (string)$this->value;