How to check if file from sftp server already exists in database
Hi! I'm trying to make a task in which I call an sftp server and check for new files in a path. I'm sending an external api request to list all the files in that path and getting their filename by creating a variable. How do I then use that variable (the filename) to check whether that file already exists in my database?
Best Answers
-
hey @chrstnstl - the file name is part of the metadata that is stored in the database. You can check for Existence with a Has Record function based on the field.name.. for example, mine field is called "pic" so pic.name is the filename
-
@chrstnstl assuming you have a text file:
1) Read the file into memory by using "get file data from resource"
2) Split the file based on the newline character
3) Create a variable that is based on the split data and apply a filter to "get" the first item in the array (e.g. path 0)
4) Create a variable that is based on the split data and apply a filter to "get the last item in the array (e.g. path of the count of the array minus one)
Manipulating files is one of those hard problems we work on in our daily State Change Pro office hours.
Answers
-
thank you for this! it worked. I have another question, for the text file I'm downloading via external api, I would like to get the first and last line of the body, is there a built-in function in xano for it? Or is my only option is to use Lambda function to do it?
-
@Ray Deck Thank you so much! This worked!
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback