Welcome to the nuBuilder Forums!

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

Another Input:file object question

Questions related to using nuBuilder Forte.
Locked
tonyd
Posts: 68
Joined: Sun Mar 04, 2018 6:38 pm

Another Input:file object question

Unread post by tonyd »

I think I get the whole concept nuBuilder uses for an Input:file object. It looks like when there is a change to an Input:file object the event fires the nuChangeFile() function in nuform.js, which in turn JSON-ifies the file data and saves it in a hidden textarea. If my understanding is correct, then would this be the place that I would want to add some code to save the file to the server? And to do that, would I be correct in assuming that I would need to ajax the file to some PHP code that would in turn save the file to the server?

What I want to do is bypass the saving of the JSON data and just save the file to the server, and just save the path to the saved file. What I don't yet understand is where in the nuBuilder code does the Input:file object get placed on the form? That is the spot that I would have to make additional changes in order to read the file back in. My goal would be much better if I could figure a way to do what I want without changing any nuBuilder code. Any ideas?

TIA
TonyD
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Another Input:file object question

Unread post by toms »

Tony,

I was faced with a similar task when I needed to upload a file to my server and then send it by email. At the end of the day, I decided not to use nuBuilder's Input FileUpload Object but went for another solution because It took about 4 minutes to upload/send a 100KB file.
It's based on this code https://gist.github.com/matteomattei/e2 ... 73b2da2921 (with slight modifications to meet my own needs)
tonyd
Posts: 68
Joined: Sun Mar 04, 2018 6:38 pm

Re: Another Input:file object question

Unread post by tonyd »

Thanks bunches toms. I got the file upload to work without too much fuss, and it is rather speedy, too. No more "Request Data Too Large" errors like I used to get trying to save the file to the database. Now I just need to figure out how to retrieve the file when the Edit form displays again. Unfortunately, my brain has shut down for the moment. :shock:
TonyD
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Another Input:file object question

Unread post by toms »

The ajax success function returns the file names (In my case just 1 file name since I disallow multiple files)
This saves the filename to a nuBuilder field:

Code: Select all

success: function (res) {
         ....
	if(result.res === true){
	   ...
$('#myfilename').val(result.data[0]).change(); 
...
}
Then create a html object that displays a link to your file on the server

<a href="path_to_server/#myfilename#" download="path_to_server/#myfilename#">Download</a>
tonyd
Posts: 68
Joined: Sun Mar 04, 2018 6:38 pm

Re: Another Input:file object question

Unread post by tonyd »

Got it. Everything works like a charm. Thanks toms.
TonyD
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Another Input:file object question

Unread post by admin »

.
Locked