How To Upload Files To An FTP Server From Knack
Hello Folks!
Today we want to share with you how to upload files and save them in an FTP server from the Knack database through a proxy.
Please keep in mind you must have some essential conditions in order to accomplish this.
We list the following requirements:
Have an FTP server configured
Web server to run endpoint that will upload files to FTP
A Knack application with an object and a form to make the post to the server
Step 1:
The first thing you need is to have the access data and credentials configured for the FTP server, which are:
host: xxxxxxx,
port: 21,
user: xxxxxx,
password: xxxxxxxx
Step 2:
Create an endpoint in NodeJS
Once you have the access data to the FTP server, the next step is to create an endpoint which will receive the file and upload it to the FTP server.
The code in the endpoint will look like this.
To see the code’s structure please enter this site:
https://github.com/SOLUNTECH/knack-ftp
Step 3: Create the app in Knack.
An object must be created containing a file type field which will be sent to the FTP Server.
Now, create a page and put a form to post to the object you just created.
Step 4
Finally, go to the JavaScript section in Knack, and add this simple code. Make sure you update the field_id with your own.
$(document).on('knack-form-submit.view_361', async function (event, view, data) { await $.ajax({ url: `${FTP_API_SERVER}ftp`, // Endpoint URL type: 'POST', // Method data: { // Body JSON file: data.field_399_raw.url, filename: data.field_399_raw.filename }, dataType: 'json' })
Are you ready to implement this from your Knack App?
Let us know how it goes…..
Let’s Make IT Happen!