Welcome to the nuBuilder Forums!

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

configure Uppy

Questions related to using nuBuilder Forte.
johan
Posts: 422
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: configure Uppy

Unread post by johan »

Kev1n

I still got the same error.
Maybe the procedure is old?

Code: Select all

// Allowed file types
$allowedTypes = [
    'image/png',
    'image/jpeg',
    'application/pdf',
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    'application/vnd.openxmlformats-officedocument.presentationml.presentation',
    'text/plain',
    'text/csv'
];

// Maximum file size
$maxFileSize = 5 * 1024 * 1024; // (5 MB)

// Target directory
$targetDirectory = $_SERVER['DOCUMENT_ROOT'] . '/';

try {

	// Sanitize file name
	$fileName = nuSanitizeFilename(basename($_FILES['file']['name']));

	// Check file size
	if ($_FILES['file']['size'] > $maxFileSize) {
		throw new Exception('Exceeded file size limit');
	}

	// Check file type
	$finfo = new finfo(FILEINFO_MIME_TYPE);
	if (!in_array($finfo->file($_FILES['file']['tmp_name']), $allowedTypes)) {
		throw new Exception('Invalid file type');
	}

	// Build target file path
	$targetFile = $targetDirectory . $fileName;

    if (move_uploaded_file($_FILES['file']['tmp_name'], $targetFile)) {
        $data = ['url' => $targetFile, 'file' => $fileName, 'message' => 'The file ' . $fileName . ' has been uploaded.'];
        http_response_code(201);
        $result = json_encode($data);
    }
    else {
        throw new Exception(nuTranslate('Unable to move the uploaded file to its final location:') . $targetFile);
    }

} catch(\Throwable $th) {

    $result = nuSetUploadError('Sorry, there was an error uploading your file.');

}
Johan
kev1n
nuBuilder Team
Posts: 4428
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 475 times
Contact:

Re: configure Uppy

Unread post by kev1n »

The PHP code looks up to date.

I understand the error message to mean that the function nuOnFileUploadComplete() has been added to your form's custom code, and inside that function, it's trying to access a message property that doesn't exist.

johan wrote: Wed Jul 02, 2025 3:08 pm
This is the error in my console

Code: Select all

uppy.min.js?ts=20250702125031:2 [Uppy] [15:03:41] TypeError: Cannot read properties of undefined (reading 'message')
    at <anonymous>:17:34
    at Array.forEach (<anonymous>)
    at nuOnFileUploadComplete (<anonymous>:16:18)
    at Function.<anonymous> (<anonymous>:36:8)
    at emitAll (uppy.min.js?ts=20250702125031:1:1483)
    at Object.emit (uppy.min.js?ts=20250702125031:1:785)
    at i.emit (uppy.min.js?ts=20250702125031:2:75026)
    at i._runUpload2 (uppy.min.js?ts=20250702125031:7:11269)
Johan
johan
Posts: 422
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: configure Uppy

Unread post by johan »

Kev1n

This is the original procedure. I made no changes to it myself.

Johan
kev1n
nuBuilder Team
Posts: 4428
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 475 times
Contact:

Re: configure Uppy

Unread post by kev1n »

I see. Just to confirm — your form’s custom code does not include a nuOnFileUploadComplete() function, correct?

Also, try creating a brand-new object with a fresh Uppy instance to see if that resolves the issue.
johan
Posts: 422
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: configure Uppy

Unread post by johan »

Kev1n

I've created a new object.
Upload to database works but not to the server.

Still got this error.
Screenshot 2025-07-02 16.39.48.png
Johan
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4428
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 475 times
Contact:

Re: configure Uppy

Unread post by kev1n »

And if you create it on a new form?
johan
Posts: 422
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: configure Uppy

Unread post by johan »

Kev1n

I've created a new fastform with the file object but with the same result.

Johan
johan
Posts: 422
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: configure Uppy

Unread post by johan »

Kev1n

In Procedure I've changed

Code: Select all

$targetDirectory = $_SERVER['DOCUMENT_ROOT'] . '/'
into

Code: Select all

$targetDirectory = '../uploads/';
That solved my problem for the upload.

After upload, the attachment disappears in the form.
How do I get an overview of the attachments belonging to my form?

Johan
kev1n
nuBuilder Team
Posts: 4428
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 475 times
Contact:

Re: configure Uppy

Unread post by kev1n »

There are several ways to display attachments. One option is to use an embedded iFrame (run object) to show the files associated with a specific record. Is it correct that multiple files can be uploaded for a record?
johan
Posts: 422
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: configure Uppy

Unread post by johan »

Kev1n

Yes multiple files are possible.
Johan
Post Reply