I am trying to get a CSV download of a database that I have.
I am literally just testing @admin-23 example:
https://www.wix.com/corvid/forum/community-discussion/database-6
here and I keep getting a 404 error.
What blows my mind is that on the forum post the button link works, but on my published site I get the 404.
Go here: https://elizabethjhay.wixsite.com/mysite-14/as-a-member
press Download under Download “Business Directory”
I backtracked in function because while I did modify the code to fit my needs I just wanted to see if I got the 404 error with everything and turns out I do.
Here is my http-functions.js code so you can see where I am trying to go after I replace @Ido’s work.
Import { ok, created, badRequest, notFound, serverError } from 'wix-http-functions';
import wixData from 'wix-data';
let csvData = "items"
export function get_businessDirectory (request) {
let options = {
"headers": {
"Content-Disposition": `attachment; filename= "list.csv"`
},
"body": csvData
};
let query = wixData.query("Chamber_Business_Directory");
if (request.query) {
var query_keys = Object.keys(request.query);
query_keys.forEach(function (entry) {
if (request.query[entry] !== "all") {
query = query.eq(entry, request.query[entry]);
}
});
}
return query
.find()
.then((results) => {
// matching items were found
if (results.items.length > 0) {
options.body = {
"items": results.items
};
return ok(options);
}
// no matching items found
options.body = {
"error": `'${request.path[0]} ${request.path[1]}' was not found`
};
return notFound(options);
})
// something went wrong
.catch((error) => {
options.body = {
"error": error
};
return serverError(options);
});
}
I am doing this because chrome is not allowing to download sandbox .csv from iframe. Otherwise I have a working modified version of this:
This is so so frustrating has anyone also encountered the 404 ?!