Server Side Downloading Files with Routing problems

Hi, I am working my way through server side downloading files with Routing. I followed the tutorial on static server side downloading with routing and that worked fine, even with Routing parameters, all is good so far.

I am taking baby steps to move forward and I wish to use Dynamic values for the Download but this has caused some unexpected results.

My routing is defined as …

image

When called from an Anchor button with the Link set to a static value…

it works beautifully and a download of the file occurs.

I then defined 4 variables in the App to check that the link will work with dynamic values rather than static values. Each valuable, for now, is set to the same values you see above.

But the effect of this is that the download will not work. When I click on the anchor button, the page blanks entirely, no error message is displayed, no file is downloaded.

I am working my way through all the documentation on this, but help is needed.

BruceX

Is the link on the button href=“…” or dmx-bind:href=“…” ?

Perhaps you could past the code for the button

Hi bpj

The anchor button is

image

When using dynamic data you need to use dynamic attributes > link option in the ui.
So the link becomes:

dmx-bind:href="'/api/apiUsers/FileUpload--uAttachment/' + varDownloadFilename.value + '/' + varDownloadFolder1.value + '/'+ varDownloadFolder2.value + '/' + varDownloadFolder3.value + '/'"

Also, when showing your code PLEASE PASTE THE CODE here, as it’s easier to copy/modify it. Don’t post screenshots of the code, when you can just paste it here.

Hi Teodor

Your instruction to paste code itself, noted. Your suggestion to change the href as made a step forward, thanks.

The code itself that I did paste above is a result of filling in the blanks here…

resulting in this in the link

/api/apiUsers/File_Upload–uAttachment/{{varDownloadFilename.value}}/{{varDownloadFolder1.value}}/{{varDownloadFolder2.value}}/{{varDownloadFolder3.value}}

btw, clicking the routing symbol again shows the routing parameters as blank despite just being filled in.

Also, I have now pasted in your custom code to replace the generated code, this caused the anchor button link to go blank.

Anyway, the custom code advanced things, but I have noticed another, maybe, a problem.

The .htaccess has been overwritten by wappler (I have saved my original copy), and wappler has not restored the original .htaccess. Should that be expected?
This was true when the static downloads were finishing cleanly. The problem arises that it leaves the web site folders and files unsecure. Should I use FileCopy to restore the original .htaccess after download or is there a better way?

I am not sure i understand your question and what do you mean by "use FileCopy to restore the original .htaccess after download"
If there is an htaccess file in your local site directory, Wappler will just add its code below the existing content of your .htaccess file.

Screenshot 2021-10-17 at 13.54.56

If there is no an .htaccess file in your local site folder, Wappler will create it and put its code inside. So in case your htaccess only exists on the server, it will be overwritten on upload ... so make sure your htaccess file exists in your local site folder.

Teodor
I did read that somewhere, that wappler adds to an existing .htaccess, but it did not do that, it replaced my .htaccess.

This is before…

Options -indexes
Options -MultiViews
RewriteRule .*files.* / [NC,F]
<FilesMatch "^php5?\.(ini|cgi)$">
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
</FilesMatch>
php_value upload_max_filesize 400M
php_value post_max_size 420M

and after

## Wappler routing
RewriteEngine On
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?api/apiUsers/File_Upload--uAttachment/([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)(?:/)?$ dmxConnect/api/apiUsers/File_Upload--uAttachment.php?filename=$1&folder1=$2&folder2=$3&folder3=$4 [QSA,NC,L]
## End Wappler routing

and .htaccess remains in the after state.

Most probably you did not have the htaccess locally and only on the server.
Just add your content in the htaccess and save it, you should be good.

Hi Teodore
The downloads are all working now.
I combined the 2 .htaccess files above with the wappler code appended after the original code.

Options -indexes
Options -MultiViews
RewriteRule .files. / [NC,F]
<FilesMatch “^php5?.(ini|cgi)$”>
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS

php_value upload_max_filesize 400M
php_value post_max_size 420M
#######################################################

Wappler routing

RewriteEngine On

Options -MultiViews

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_METHOD} GET
RewriteRule ^/?api/apiUsers/File_Upload–uAttachment/([^/]+?)/([^/]+?)/([^/]+?)/([^/]+?)(?:/)?$ dmxConnect/api/apiUsers/File_Upload–uAttachment.php?filename=$1&folder1=$2&folder2=$3&folder3=$4 [QSA,NC,L]

End Wappler routing

I tested a download and I got a 403 forbidden, it would seem that the wappler code does not override the original code. But on the other hand the htaccess was preserved.

Hi Teodor
I have managed to solve the security issues with .htaccess (I believe so anyway- time will tell), now files can only be managed from within the web app and cannot be accessed directly on the web site.

Now I wish to tackle the issue of URL disguising.

On my file upload page, when I hover over the download icon, the full path to the underlying file is revealed.

image

I wish to disguise the yellow bits in the above image. I have tried a few ideas but nothing I have tried has worked so far. The tutorials on routing concentrate on improving SEO by disguising a parameter name and emphasizing a parameter value in a URL. This situation is different.

Do you have any hints of how to convert the url to something like…

https://marama-cloud.com/downloadfile/smscheftest.php/Demo

Currently my routing is

image

with the Path and URL being…

Path
/api/apiUsers/File_Upload–uAttachment/:filename/:folder1/:folder2/:folder3

Url
/dmxConnect/api/apiUsers/File_Upload–uAttachment.php