Page 1 of 2

problem downloading/opening files.

Posted: Fri Dec 20, 2024 3:33 pm
by jameslast29
Hello All,

I recently migrated several Nubuilder instances.
The previous version was on Mariadb, the new one is on Google cloud sql
Version info of the new version:
db version: V.4.5-2024.06.09.00
file version: V.4.5-2024.06.08.10
mysql version: 8.0
php verion: 8.1
os : Debian12
Further config info: see below.

The problem I’m facing is that I cannot download/open files.
When initially clicking on the file, nothing happens.
When I checkmark the file, then uncheck it, the the file appears in bold. Then when clicking
it again I can download it.

I have made a video of this, I hope this helps:

(the opening of the file in the end is not shown on the video for some reason)
uploading files works just fine, so I think it is not a permission -issue.

I appreciate any advise on this.

Greetings, j.

config info:




Code: Select all

// ** Configuration: Modify if necessary
// *****************************************

var uploadFolder = 'libs/upload/documents/';
var idFileName = 'bl_name';
var idFileId = 'bl_files_id';
var idSubForm = 'sample_files';

// *****************************************

var idRowFileName;
var idRowFileId;

function uploadFile(event) {
    var td = $(event.target);
    var t = td.attr('data-nu-prefix');

    idRowFileName = t + idFileName;
    idRowFileId = t + idFileId;

    $("#fileToUpload").click();

}

function createDownloadLink(field, folder, fileId, fileName) {
    $('#' + field)
    .css({
        "text-decoration": "underline"
    })
    .css('cursor', 'pointer')
    .off('click')
    .attr({
        fileName: fileName,
        fileId: fileId,
        folder: folder
    })
    .attr('readonly', 'readonly')
    .click(function (event) {
        var link = $(this).attr('fileid') + '_' + $(this).attr('fileName');
        // downloadFile($(this).attr('folder') + $(this).attr('fileid') + '_' + $(this).attr('fileName'), $(this).attr('fileName'));
        var url = '/vrijwilligers/libs/download.php?file=' + link;
        downloadFile(url);
    });

}

function addDownloadLinks(subform) {
    document.cookie = "uid=#USER_ID#";
    var sf = nuSubformObject(subform);

    var cName = sf.fields.indexOf(idFileName);
    var cId = sf.fields.indexOf(idFileId);

    for (var i = 0; i < sf.rows.length; i++) {

        var fileId = sf.rows[i][cId];
        var fileName = sf.rows[i][cName];

        if (fileName !== '') {
            createDownloadLink(idSubForm + nuPad3(i) + idFileName, uploadFolder, fileId, fileName);
        }
    }
}

function downloadFile(url) {
    window.open(url, '_blank');
    //     var a = document.createElement("a");
    //     a.href = url;
    //     a.setAttribute("download", filename);
    //     document.body.appendChild(a);
    //     a.click();
    //     document.body.removeChild(a);
}

if (nuFormType() == 'edit') {
    addDownloadLinks(idSubForm);
} else {

    if (typeof nuStopBrowserResize == 'function') {
        nuStopBrowserResize();
    }

}

Re: problem downloading/opening files.

Posted: Fri Dec 20, 2024 7:29 pm
by steven
hI jameslast29,

Can you upload a copy of the database that has this problem?


Steven

Re: problem downloading/opening files.

Posted: Sat Dec 21, 2024 8:40 am
by kev1n
I have reproduced the issue in a test environment, but the described problem does not occur for me. To debug the issue, insert `debugger;` at appropriate points in the code so that execution stops, allowing you to check whether variables contain the correct values and if events are being triggered.

Alternatively, instead of sharing the entire database, you can provide the SQL from the form using the "cloner", as well as a dump of the tables/database schema. Make sure to remove any confidential data beforehand. Let me know if you have any questions about this.

Re: problem downloading/opening files.

Posted: Mon Jan 06, 2025 3:49 pm
by jameslast29
Hello,

first of all all the best in the new year & I apologise for not replying sooner.

I have checked with my boss and I am not allowed to share the database.
About the second option: I see a "kopie" button and then "cloning" appears in red at the top but nothing else seems to be happening.
Can you please provide more instructions on the cloning and dumping part?

Many thanks.
Greetings, j.

Re: problem downloading/opening files.

Posted: Tue Jan 07, 2025 11:06 am
by kev1n
To export a table's structure in phpMyAdmin, follow these steps:

1. Open phpMyAdmin:
2. Choose the Table:
Click on the table name from the list to select it.
3. Go to the Export Tab:
After selecting the table, click the Export tab at the top of the page.
4. Select Export Method:
Choose Custom export method.
5. Custom Export Settings:
Under the Custom export method:
Output: Leave it as SQL.
In the Data section, select "Structure only". This ensures no data is included in the export. (unless the data can be shared with us)
6. Export the File:
Scroll down and click Go to download the SQL file containing only the structure of the table.

If your form uses other tables, repeat the above steps for all tables.


To export your form using the Cloner, follow these steps:

1. Open the Cloner by navigating to Database Button → Cloner.
2. Click Add.
3. Select the Source Form you want to export.
4. Check the Subforms option.
5. Click Run.

After exporting, upload both the form dump and the table dump here as a zipped file.

Re: problem downloading/opening files.

Posted: Tue Jan 07, 2025 1:08 pm
by jameslast29
Hello,

thanks again for helping us out.
Here are the requested files
I would like to add that the problem does not occur when I copy the /var/log/www/nubuilder files from
the old setup to the new setup.

Greetings, j.

Re: problem downloading/opening files.

Posted: Tue Jan 07, 2025 6:25 pm
by kev1n
Thanks! Could you also share vrijwilligers/libs/download.php ?

Re: problem downloading/opening files.

Posted: Wed Jan 08, 2025 2:29 pm
by jameslast29
Hello,

this is the content of download.php:



<?php

$uploaddir = './upload/documents/';

#foreach ($_COOKIE as $key=>$val)
# {
# echo $key.' is '.$val."<br>\n";
#}

session_start();
# print_r($_SESSION);

if (!isset($_SESSION['nubuilder_session_data'])) {
http_response_code(403);
echo "NOT AUTHORIZED";
die();
}


if (preg_match('/^file/', $_GET['file'])) {
$filename = $uploaddir . '0_' . $_GET['file'];
} else {
$filename = $uploaddir . $_GET['file'];
}

if (file_exists($filename)) {
//Define header information
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: 0");
header('Content-Disposition: attachment; filename="'.basename($filename).'"');
header('Content-Length: ' . filesize($filename));
header('Pragma: public');

//Clear system output buffer
flush();

//Read the size of the file
readfile($filename);
} else {
echo "file does not exist: " . $_GET['file'];
}

?>

Re: problem downloading/opening files.

Posted: Thu Jan 16, 2025 10:04 am
by jameslast29
Hello,

do you maybe have further instructions for me; things I could try, howto generate more logs files?
Would it help if I upgraded to php8.2 of 8.3?

Greetnigs, j.

Re: problem downloading/opening files.

Posted: Thu Jan 16, 2025 1:20 pm
by Janusz
Do you have nuBuilder folders/files owner set to www-data
chown -R www-data:www-data * (run at the main nuBuilder folder level)
for errors you can check apache logs on Debian server:
tail -n 20 /var/log/apache2/access.log
cat /var/log/apache2/access.log
and check the nubuilder debug: Ctrl+Shift+d

there should be no difference between php8.2 and 8.3 - anyway I run 8.3 and everything works fine