Generate CSV file for download
Comments
-
Use the function set http header and define this as the header:
Content-Disposition: attachment;filename="example.csv"
(where example is the name of your csv file) -
Thank you, Michael. How do I embed the content of the csv file?
-
Can you elaborate on what you mean?
-
Actually, I was able to get the content embedded. I just couldn't do it inside Xano when I clicked the "Download" button.
Now, the file that is returned is still in JSON. This means that I will have to manually manipulate the content of the JSON into a comma-delimited file before returning. Correct? -
Take a look at this snippet for an example of also using the csv_create filter:
https://www.xano.com/snippet/ufiacxww/ -
Thank you so much.
-
My apologies. I didn't see the csv_create filter in the documentation.
-
BTW, you may want to add "csv" to the search keywords. These CSV filters didn't show up when I searched the documentation. Thank you.
-
Thanks to your help, I was able to create a generic function to convert a JSON array to a csv. I am sharing the snippet here with others:
https://www.xano.com/snippet/WFSLV4nd/ -
awesome!!
-
- when a value contains a space (ex van staden) it gets enclosed ("van staden") with whatever you configure under the enclosure section under the CSV_Create filter. I have tried numerous option to trim this but Xano seems not to like this. What is the right way of solving this under the CSV_create filter
-
Riann, what is the end result you're expecting from a value with space? You mentioned "trim". Do you want to trim the value instead?
-
Yes I am also curious what is the end result you'd be expecting here?
-
Expecting van staden in the csv file without ""
-
I don't know how to do it in one step. But perhaps you can use the regex_replace or string replace filter to get rid of the extra quotes perhaps. You can eliminate the quotes with the patterns and .
-
it seems the CSV_create does not like using other filters unless I am doing it incorrectly - lets see what advice will be
-
Did you get a solution?
-
hey there's a Snippet on this you can download with a helper tutorial so you can install it to your instance. Here's the page to the snippet: https://www.xano.com/snippet/LiPGIfYL/
And the helper video: -
I tried using the snippet, sending a json payload from Bubble.
When I send one "json" eg
{
"Sample Number": "1",
"Field": "3415",
"Depth": "N/A",
"pH": 5.17,
"pH Unit:": "CaCL2",
"Phosphorus": 29.93,
"Potassium": 78.72
}
I get the file back 100%, but when I send more than one "json" eg
{
"Sample Number": "1",
"Field": "3415",
"Depth": "N/A",
"pH": 5.17,
"pH Unit:": "CaCL2",
"Phosphorus": 29.93,
"Potassium": 78.72
}, {
"Sample Number": "2",
"Field": "3415",
"Depth": "N/A",
"pH": 5.17,
"pH Unit:": "CaCL2",
"Phosphorus": 29.93,
"Potassium": 78.72
}
the csv is empty, no header, nothing.
Any advice? Thx.
-
Not sure which snippet you used, but please make sure that you send in an object array.
[{object 1},{object 2},{object 3}]
I was able to get the result like this:
"Sample Number",Field,Depth,pH,"pH Unit:",Phosphorus,Potassium
1,3415,N/A,5.17,CaCL2,29.93,78.72
2,3415,N/A,5.17,CaCL2,29.93,78.72
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