Another Input:file object question

Questions related to using nuBuilder Forte.

Another Input:file object question

Postby tonyd » Tue Mar 13, 2018 8:14 pm

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
tonyd
 
Posts: 59
Joined: Mon Mar 05, 2018 3:08 am

Re: Another Input:file object question

Postby toms » Tue Mar 13, 2018 9:04 pm

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)
toms
Just like in real life, a little thank-you will go a long way. If an answer proved helpful to you, we would definitely be thrilled to receive a positive reaction from you. Besides, a thank-you will signal to other users that you were already helped.
toms
 
Posts: 675
Joined: Wed Nov 08, 2017 8:57 pm

Re: Another Input:file object question

Postby tonyd » Wed Mar 14, 2018 12:22 am

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
tonyd
 
Posts: 59
Joined: Mon Mar 05, 2018 3:08 am

Re: Another Input:file object question

Postby toms » Wed Mar 14, 2018 2:13 pm

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>
toms
Just like in real life, a little thank-you will go a long way. If an answer proved helpful to you, we would definitely be thrilled to receive a positive reaction from you. Besides, a thank-you will signal to other users that you were already helped.
toms
 
Posts: 675
Joined: Wed Nov 08, 2017 8:57 pm

Re: Another Input:file object question

Postby tonyd » Wed Mar 14, 2018 7:15 pm

Got it. Everything works like a charm. Thanks toms.
TonyD
tonyd
 
Posts: 59
Joined: Mon Mar 05, 2018 3:08 am

Re: Another Input:file object question

Postby admin » Wed Mar 14, 2018 9:17 pm

.
admin
Site Admin
 
Posts: 2732
Joined: Mon Jun 15, 2009 9:53 am


Return to General