Server connect Routing for file download action Bug

With referral to the below post and the thread, I have tried everything I can to find a syntax mistake on my end after following the tutorial a couple of times and I keep on getting the file not found error despite there being a file in a folder and the route displaying correctly. I am out of options and therefor posting as bug unless the way routing is done has changed from v4 to v5 somehow.

If someone can just try this on their end and confirm it works or not. Thanks

What kind of project is it? (NodeJS/PHP/ASP) (Mobile/Web)

Node.js web

You use the full path in the url, the params are parts from the url split by /. The Path /api/members/documentDownload/:filepath will match /api/members/documentDownload/doc.pdf, but not /api/members/documentDownload/folder/doc.pdf.

Try changing the Path in the router to /api/members/documentDownload/:filepath(.*) which should match anything.

Made changes, but still no luckj. Could it be because I am using the path I saved on upload as the url for download?

Here is my setup for route:

Setup for Server action:

My anchor link on the page:

<a dmx-text="filename" dmx-bind:href="'/api/members/documentDownload'+Url"></a>

The db entry:

And my error:

{"status":"404","message":"/api/members/documentDownload/public/uploads/bd16f04e45f0c2b1ecc36c8df4815ee4/PlatinumPOS_Quote_-_The_Staffordshire_QT07031306_2.pdf not found."}

If you have the file url in a database column just create a dynamic link

I always use the “download” attribute, it gives less headaches.

<a dmx-text="filename" dmx-bind:href="{{Url}}" download></a>
1 Like

Set for path /api/members/documentDownload/:filepath(*).
The File Path in the download step should be {{$_PARAM.filepath}}.

If I change the get VAR to param VAR, the front end does not allow me to put my dynamic file path:

The above is where I select the dynamic link on the front end

With a GET you can add your dynamic value, param not

With your code I get a json file downloaded with the same file not found error syntax.

This is because it is pointing to a route, you don’t need a route for this. Bind the file on the frontend.

Don’t think it is. This is my code:

<a dmx-text="filename" dmx-bind:href="{{Url}}" download></a>

Show me the result of this variable {{Url}}, What does she return?

Return this /public/uploads/bd16f04e45f0c2b1ecc36c8df4815ee4/PlatinumPOS_Quote_-_The_Staffordshire_QT07031306_2.pdf ?

try this

<a dmx-bind:href="https://yourdomain.com{{Url.replace('/public', '')}}" download="">Download</a>
1 Like

/public/uploads/bd16f04e45f0c2b1ecc36c8df4815ee4/PlatinumPOS_Quote_-_The_Staffordshire_QT07031306_2.pdf

Above is the output of URL.

Thanks, your solution works. I just left out the domain name and it also works:

<a dmx-bind:href="{{Url.replace('/public', '')}}" download="">Download</a>

Why did you save the full path in the database? If the file is in the public folder and everyone may download the file you could just store the url which you then can directly use on a download link.

That is what I now learned through this exploration. Question based on your comment: So if I save just the file name to the database and save the file in a uploads folder in the root folder of the site, I would be able to use the server side routing which I tried doing?

It depends on your use-case. If everyone may access the files you can upload/store them in the public folder, then you can access them directly. If you want more security that only logged in users can access the file or do tracking, you probably then want to place the files outside the public folder so that it is not accessible from the internet. You then need to create a server action that serves the file, you can add here extra security, do tracking and other things.