Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Uppy procedure & form data

Questions related to customising nuBuilder Forte with JavaScript or PHP.
vario
Posts: 148
Joined: Mon Dec 05, 2011 12:23 pm
Location: Newton Abbot, UK
Has thanked: 1 time
Been thanked: 1 time

Re: Uppy procedure & form data

Unread post 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.
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Uppy procedure & form data

Unread post by kev1n »

If you output the $cprid variable with nuDebug($cprid), will you see an empty string in nuDebug Results?
vario
Posts: 148
Joined: Mon Dec 05, 2011 12:23 pm
Location: Newton Abbot, UK
Has thanked: 1 time
Been thanked: 1 time

Re: Uppy procedure & form data

Unread post 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..
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Uppy procedure & form data

Unread post 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 })
        });
vario
Posts: 148
Joined: Mon Dec 05, 2011 12:23 pm
Location: Newton Abbot, UK
Has thanked: 1 time
Been thanked: 1 time

Re: Uppy procedure & form data

Unread post 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?
miditt
Posts: 3
Joined: Thu Dec 30, 2021 11:49 am

Re: Uppy procedure & form data

Unread post by miditt »

Try this:

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

uppy.setMeta({ procedure: 'your_procedure_name', cprid: '#cprid#' })
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: Uppy procedure & form data

Unread post 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
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Uppy procedure & form data

Unread post by kev1n »

Hi,

Do you need to retrieve the file names on server side (PHP) oder client side (JS) ?
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: Uppy procedure & form data

Unread post by yvesf »

I need to retrieve the file names on the client side .
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Uppy procedure & form data

Unread post by kev1n »

Declare a function called "nuOnFileUploadComplete" as shown here:

viewtopic.php?p=27635#p27635
Post Reply