Page 1 of 2

file upload to server

Posted: Mon Feb 25, 2019 2:41 pm
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

Re: file upload to server

Posted: Mon Feb 25, 2019 2:56 pm
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#")

Re: file upload to server

Posted: Tue Feb 26, 2019 4:53 pm
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

Re: file upload to server

Posted: Wed Feb 27, 2019 9:18 am
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

Re: file upload to server

Posted: Fri Mar 01, 2019 3:56 pm
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?

Re: file upload to server

Posted: Fri Mar 01, 2019 4:31 pm
by kev1n
If you click on this "VM"-link, you'll see the line the causes the error.
err.png

Re: file upload to server

Posted: Fri Mar 01, 2019 6:08 pm
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

Re: file upload to server

Posted: Fri Mar 01, 2019 7:06 pm
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.

Re: file upload to server

Posted: Mon Mar 04, 2019 8:49 am
by johan
Kevin
We find our error in the object (Html) part.
Now we can try the rest.
Thanks
Johan

Re: file upload to server

Posted: Mon Mar 11, 2019 10:27 am
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