Page 2 of 3

Re: Uppy procedure & form data

Posted: Sat Nov 05, 2022 2:59 pm
by vario

Code: Select all

<div id="#uppy_div#"></div>

<script>
    
    nuInitUppy();
    
    function nuInitUppy() {

        const $objId= $('#' + '#this_object_id#');
        const target = '#' + '#uppy_div#';
    
        let uppy = new Uppy.Core();
    
        uppy.use(Uppy.Dashboard, {
                inline: true
                , bundle: true
                , height: $objId.cssNumber('height')
                , width: $objId.cssNumber('width')
                , target: target
                , showProgressDetails: true
                , replaceTargetContent: true
                , method: 'post'
            })
            .use(Uppy.XHRUpload, {
                endpoint: 'core/nuapi.php'
            })
    
        uppy.setMeta({ procedure: 'php_UploadFuelTransactions', cprid: document.getElementById('cpr_id').value, session_id: window.nuSESSION })
    
        uppy.on('complete', (result) => {
    
            if (window.nuOnFileUploadComplete) {
                nuOnFileUploadComplete('FS', $objId.attr('id'), result);
            }
    
        })

    }

</script>
The field cpr_id is a Select object, and in the PHP I've just got the POST variables assigned as you suggest (this is the part that had stumped me):

Code: Select all

$cprid = isset($_POST["cprid"]) ? $_POST["cprid"] : '';
Neil.

Re: Uppy procedure & form data

Posted: Sun Nov 06, 2022 7:33 am
by kev1n
If you output the $cprid variable with nuDebug($cprid), will you see an empty string in nuDebug Results?

Re: Uppy procedure & form data

Posted: Sun Nov 06, 2022 10:06 am
by vario
Yes. If I concatenate with another character (e.g period) as

Code: Select all

nuDebug('.'.$cprid.'.')
I get

Code: Select all

[0] : ..
in deb_message..

Re: Uppy procedure & form data

Posted: Sun Nov 06, 2022 7:51 pm
by kev1n
Replace

Code: Select all

 uppy.setMeta({ procedure: 'php_UploadFuelTransactions', cprid: document.getElementById('cpr_id').value, session_id: window.nuSESSION })
With

Code: Select all

uppy.on('file-added', (file) =>{
            uppy.setMeta({ procedure: 'php_UploadFuelTransactions', cprid: nuGetValue('cpr_id'), session_id: window.nuSESSION })
        });

Re: Uppy procedure & form data

Posted: Sat Nov 19, 2022 3:41 pm
by vario
As Uppy is new to me and a little above my Javascript skill level, I worked around the problem by moving the upload to a form where I can use #RECORD_ID# instead of the select object! Thanks anyway and I'll try this sometime.

P.S Not strictly relevant but I don't understand why the Uppy "catch" has "\Throwable $th"? I can't get usable error messages back to the form (e.g when I load an invalid file type) and why the backslash?

Re: Uppy procedure & form data

Posted: Mon Nov 28, 2022 5:51 pm
by miditt
Try this:

nuSetProperty('cprid', $('#cpr_id').val(), true) ;

uppy.setMeta({ procedure: 'your_procedure_name', cprid: '#cprid#' })

Re: Uppy procedure & form data

Posted: Fri Dec 30, 2022 3:54 am
by yvesf
Hello,

I have modified my Uppy procedure and the upload on the server works like a charm. I would like to retrieve the names of the files uploaded. I see those on the server. When I attach, I have their names, I upload, see those coming on the root document server but once done, their names have disappeared. How can I retrieve the names in order to construct the url to the file. Anyone has got an idea ? Many thanks for your help.

Yves

Re: Uppy procedure & form data

Posted: Fri Dec 30, 2022 9:51 am
by kev1n
Hi,

Do you need to retrieve the file names on server side (PHP) oder client side (JS) ?

Re: Uppy procedure & form data

Posted: Fri Dec 30, 2022 11:47 am
by yvesf
I need to retrieve the file names on the client side .

Re: Uppy procedure & form data

Posted: Fri Dec 30, 2022 12:06 pm
by kev1n
Declare a function called "nuOnFileUploadComplete" as shown here:

viewtopic.php?p=27635#p27635