CallbackAfterUpload not launched?

CallBackAfterUpload not working at all. When I lauch this code, the upload is do on the server normally.
I think that the Callback is not lauched.

Hello, it’s very strange, this is my function in my CI controller

public function news()
    {
        $crud = $this->_getGroceryCrudEnterprise();
        // Configurer Grocery CRUD
        $crud->setTable('news');
        $crud->setSubject('News');
        $crud->displayAs('video', 'Vidéo');
        $crud->setTexteditor(['texte']);
        $crud->setTheme('bootstrap-v4');
        $crud->fieldType('la_date', 'date');
        $crud->requiredFields(['titre']);
        $uploadValidations = [
            'maxUploadSize' => '20M', // 20 Mega Bytes
            'minUploadSize' => '1K', // 1 Kilo Byte
            'allowedFileTypes' => ['gif', 'jpeg', 'jpg', 'png']
        ];
        $crud->setFieldUpload('photo','assets/news/photos', base_url() . 'assets/news/photos/', $uploadValidations);

        $crud->callbackAfterUpload(function ($result) {
            var_dump($result);
            die;
        });
        
       
         // Afficher la liste des enregistrements
        $output = $crud->render();
        return $this->_superadmin_output($output);
       
    }

Hello, I trying with CallbackAfterUpdate and it’s working. So it’s not a general problem with callback, only with callback after Upload. Even the file is really uploaded.

Hello @lolo57 ,

I can’t reproduce the issue that you are describing. Maybe it has to do with mail function it self? I’ve tried with this code and it is working:

$crud->callbackAfterUpload(function () {
    // Song from Red Hot Chili Peppers :)
    var_dump("🎵 How loooooong, how loooooong will I slide?
Separate my side, I don't
I don't believe it's bad
Slit my throat it's all I ever 🎵");
    die;
});

And the message is displayed after the upload. Can you try to var_dump() a message to see if this appears to your screen?

Also please keep in mind that this callback is only if you have a file to upload. For example if you have a file to upload on “Browse” button. If you are editing a record and the file is already uploaded the callback will not be triggered. Hope it make sense.

Hello,

It’s the firtst test i had doing. But nothing is displayed, and the program continue as if there is no die !. The upload is doing fine, but not the callback, very strange.
Now I have writed a little workaround, I downscale my picture a the reading of news. But it’s not a perfect solution, and there is vraissembly a problem somewhere in my grocerycrud install ?

Any Idea ?

Hello @lolo57 ,

After searching around I think I’ve find the issue of why this is not working🕵️ (and more specifically this post Upload field. How to store the full path in database? - #4 by johnny ). There was a bug on callbacks for upload and they weren’t working at all. This is not clearly mentioned at the documentation, either at the forums. This is fixed on version 3.0.9 and later. I would suggest to upgrade to the latest version (3.0.10) from here: User's Page Login

Let me know if after the upgrade you are still having the same issues.

Regards
Johnny

Hello Jonnny,

Thank you for your help, is there a way to display my actual version of GroceryCrud, it seems that : echo GroceryCrud::VERSION not yet working in V3.xx

Thank you.

Hello @lolo57 ,

Yes this was an issue reported by @larasmith and I’ve fixed it starting from version 3.0.10 and later. So only after this version onwards you will see the version.

So you can now see the version from PHP. Another way to check the version in older versions is to check the folder public/vendor/grocery-crud/static/js/ and search for a file with name “bundle” so for example at the last version we use the file “bundle.v3.0.10.60706269.js” so v3.0.10 is the Grocery CRUD version you use.