Marcel, that's not the problem.
The routing, link and server connect setup look correct on the screenshots.
This is an issue with NodeJS and we are going to check it.
If the resolution will take time, please let me know if there is way around this by changing the code. I will be unable to move forward until this step is done.
Well, it will probably be fixed really soon. Skip the download part for now and just continue with the rest of your project
You need to pass the filename in the querystring as defined in your server connect.
<a class="btn" dmx-bind:href="api/dwnldReport/?filename={{varDownloadReport.value}}">Anchor Button</a>
If you want to use the route parameter then you have to use $_PARAM
in the server action instead of $_GET
.
Thanks Patrick
First Part worked. I can download files now.
I dont understand the second part completely. Will try this later.
You specified a route with the path api/dwnldReport/:filename
. To access the parameter :filename
from the path you need to use $_PARAM.filename
.
Lets say the url is api/dwnldReport/myfile?filename=report.pdf
, then the variables can be accessed as:
$_PARAM.filename = 'myfile'
$_GET.filename = 'report.pdf'
$_PARAM
gets the route path parameter and $_GET
will get the parameter from the querystring.
I think the confusion is because of the routing in PHP/ASP, there the route parameter becomes a $_GET
. The difference with NodeJS is that PHP/ASP doesn’t actually do routing, it rewrites the url.
An route with the path api/dwnldReport/:filename
in PHP would be rewritten to dmxConnect/api/dwnldReport.php?filename=...
, so the route parameter becomes a querystring parameter and is accessed with $_GET
in server connect.
@Teodor and @patrick may I ask your help by bumping up this topic?
I have NodeJS Server (Wappler 4.01) model and I was trying to follow this tutorial Wappler Documentation - File Downloads with Server Connect and everything that was written above but still I couldn't achieve to pass filename as parameter.
I get same 404 error;
{
"status": "404",
"message": "/api/address_book/download_agreement/933080umEN.pdf not found."
}
My API Action look like this:
And routing like this:
My Download button anchor Dynamic Attribute Link looks like this:
'api/address_book/download_agreement/'+agreement_file_path
What I'm missing?
What server model are you using?
Please try what patrick suggested:
So in your anchor tag use $_PARAM instead of $_GET
Server model: NodeJS
@Teodor to be honest this solution quite confusing - what and where should I change?
So I've changed anchor link, now it's looks like this:
<a href="#" class="btn" dmx-bind:href="'api/address_book/download_agreement/'+agreement_file_path">Anchor Button</a>
I've changed routing link now it's look like this:
/api/address_book/download_agreement/$_PARAM.filename
I'm getting same 404 error.
{
"status": "404",
"message": "/api/address_book/download_agreement/933080umEN.pdf not found."
}
Should I change parameter filepath parameter in Server Action from GET to PARAM too?
Yes, as explained here:
Your routing path should remain as it was ...
So I've changed Server Action to use $_PARAM
I've set routing rule as: /api/address_book/download_agreement/$_PARAM.filename
My current link to download is: <a href="#" class="btn" dmx-bind:href="'api/address_book/download_agreement/'+agreement_file_path">Anchor Button</a>
And I'm still getting 400 error:
{
"status": "404",
"message": "/api/address_book/download_agreement/933080umEN.pdf not found."
}
Your routing path should be
/api/address_book/download_agreement/:filename
OMG It worked!!!
Thank you very much @Teodor