Welcome to the nuBuilder Forums!

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

file upload to server

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

file upload to server

Unread post by johan »

Hi, we are trying to make file uploads work as suggested on the forum here:
https://forums.nubuilder.cloud/viewtopic. ... d&start=10

But, we would like to allow multiple files to be added to the same record, so we created a table that will link recordid and uploaded file (file uploads get a unique name).
The problem we are having is that the name of the file is not available in the after-save handlers.

Where should we insert the code to write the record to the files table we created?
Johan
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 447 times
Contact:

Re: file upload to server

Unread post by kev1n »

In Javascript, use an array to store the file names:

Code: Select all

// Create an array
var files = new Array;

// Push the file names to the array
files.push(first_file);
files.push(second_file);
// ....

// Convert the array to a JSON string and set a hash cookie:
var j = JSON.stringify(files);
nuSetProperty('myfiles',j);
In PHP, use json_decode() to decode the JSON string an you want to loop through the array, use a foreach loop.

Code: Select all

$f = json_decode("#myfiles#")
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: file upload to server

Unread post by johan »

Kevin
Thanks for your reply.
Where should we inject that java code in the linked solution? I assume it needs to go somewhere in the code that calls process_file.php?

Johan
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 447 times
Contact:

Re: file upload to server

Unread post by kev1n »

johan wrote:Where should we inject that java code in the linked solution? I assume it needs to go somewhere in the code that calls process_file.php?
Within the ajax success callback (added lines flagged with *ADD* )
ajaxsuccess.png
You do not have the required permissions to view the files attached to this post.
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: file upload to server

Unread post by johan »

Kevin
I changed the HTML code to that in the image, but now the upload fails, the error in the console is:
ReferenceError: f is not defined

What did I miss?
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 447 times
Contact:

Re: file upload to server

Unread post by kev1n »

If you click on this "VM"-link, you'll see the line the causes the error.
err.png
You do not have the required permissions to view the files attached to this post.
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: file upload to server

Unread post by johan »

Kevin
My error points to
function nuLoginRequest(u, p){
$.ajax({
async : true,
dataType : "json",
url : "nuapi.php",
method : "POST",
data : {nuSTATE :
{call_type : 'login',
username : arguments.length 0 ? $('#nuusername').val() : u,
password : arguments.length 0 ? $('#nupassword').val() : p,
login_form_id : nuLoginF,
login_record_id : nuLoginR}
},
dataType : "json",
I don't see any f
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 447 times
Contact:

Re: file upload to server

Unread post by kev1n »

I don't know what your code looks like and where you added it. Without that information it's next to impossible to know what causes this error.
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: file upload to server

Unread post by johan »

Kevin
We find our error in the object (Html) part.
Now we can try the rest.
Thanks
Johan
johan
Posts: 399
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: file upload to server

Unread post by johan »

Kevin
"We want to write data to another table using the after save handler where we have the recordid available. How would we do that? Specificly, looking at how to use the SQL connection Nubuilder already has
Post Reply