getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.27k stars 167 forks source link

Zip file upload throws Call to a member function createFile() on null #4416

Closed GiantCrocodile closed 2 years ago

GiantCrocodile commented 2 years ago

Description

When you upload kirby-3.7.0-rc.2.zip to a page's file field, you get an error.

Expected behavior
No error when you choose to upload this file.

Screenshots
grafik

grafik

To reproduce

  1. Go to a page with a Files field
  2. decide to upload the zip file "kirby-3.7.0-rc.2.zip"
  3. Error occurs in browser console and as a popup/dialog

Your setup

Kirby Version
[3.7.0-rc.2]

Console output

GEThttp://localhost/kirby/api/pages/blog+test/fields/files?page=0
[HTTP/1.1 400 Bad Request 314ms]

Object { status: "error", message: "Your query must return a set of files", code: 400, exception: "Kirby\\Exception\\InvalidArgumentException", key: "error.invalidArgument", file: "/kirby/kirby/src/Cms/FilePicker.php", line: 65, details: [], route: "pages/([a-zA-Z0-9\\.\\-_%= \\+\\@\\(\\)]+)/fields/([a-zA-Z0-9\\.\\-_%= \\+\\@\\(\\)]+)(?:/(.*))?" }
[index.js:1:6580](http://localhost/kirby/media/panel/0c54e85478d4103bb6683e538994010d/js/index.js)
XHRPOSThttp://localhost/kirby/api//pages/blog+test/fields/files/upload
[HTTP/1.1 500 Internal Server Error 314ms]

XHRPOSThttp://localhost/kirby/api//pages/blog+test/fields/files/upload
[HTTP/1.1 500 Internal Server Error 394ms]

Your system (please complete the following information) Windows 11 WAMP setup

Additional context
If you choose to select a file from a list of existing files, it throws an "Your query must return a set of files" error if the query returns no files. That one might be on purpose/by design.

afbora commented 2 years ago

I can't reproduce the issue. Do you have any plugins? Do you still get same error on plain/starter kit?

GiantCrocodile commented 2 years ago

@afbora I tried with starterkit and it did work there without issues (3.6.6 and 3.7.0 rc2). Then I retried my own page and I think I found the issue but I don't understand it yet.

Try to select a already uploaded file (instead of upload) which will cause because there are no files uploaded previously (query will fail). If you then try to upload a zip file for first time, it tells you there was an internal error and when you try it a second time with a different zip file, you get the error I have posted in this issue.

I suspect this is related to this query in my blueprint:

          children:
            type: pages
            query: page.childrenAndDrafts
          files:
            type: files
            query: page.children.find('test').images
            uploads:
              parent: page.children.find('test')

I'm not sure why I have this in (looks like some old code) but I suspect it shouldn't break it?

EDIT: This would then be linked to my tiny comment hook plug in .... looks like I have to investigate this next few days :/.

afbora commented 2 years ago

@GiantCrocodile Did you try childrenAndDrafts instead children. I'm pretty sure this issue related with this.

fields:  
  download:
    type: files
    query: site.childrenAndDrafts.find('test').images
    uploads:
        parent: site.childrenAndDrafts.find('test')
GiantCrocodile commented 2 years ago

@afbora I tried your query and parent example (not just replacing children with childrenAndDrafts but also the site part). This does throw the same error as before. When I just take childrenAndDrafts instead children it doesn't help as well.

In case you are interested, I've sent you a minimal example.

afbora commented 2 years ago

This was just example. You need to adapt based your application. childrenAndDrafts didn't work because test page is not in root but under the blog page blog/test.

⚠️ Note that regular queries cannot find draft pages. You need to use custom queries like index(true) or childrenAndDrafts. Following examples should work (tested on your app):

files:
  type: files
  query: site.index(true).find('blog/test').images
  uploads:
    parent: site.index(true).find('blog/test')

or

files:
  type: files
  query: kirby.page('blog').childrenAndDrafts.find('test').images
  uploads:
    parent: kirby.page('blog').childrenAndDrafts.find('test')
GiantCrocodile commented 2 years ago

@afbora Now I do understand why it throws an error like Call to a member function createFile() on null. Thank you for helping with this. I tried different things out and it makes sense now/works now.

When I reduce the field to look like

          files:
            type: files

it works to upload or select files fine for "kirby-3.7.0-rc.2.zip". Could it be that uploading starterkit-main.zip fails with an Internal Server Error (see browser console) because it is ~ 11 MB and thus exceeds file limits? If so, is the missing helpful error message by design? After upload it just says:

Fehler

    starterkit-main.zip

    Es wurden keine Dateien hochgeladen 

(Saying "Error starterkit-main.zip No file has been uploaded" without any explanation or hint if it's by design, an server error or some other issue). If this is by design, we can treat it as case closed. Thank you for your great support once again!

afbora commented 2 years ago

(Saying "Error starterkit-main.zip No file has been uploaded" without any explanation or hint if it's by design, an server error or some other issue). If this is by design, we can treat it as case closed.

I think, we should handle/review this in a separate issue.