Unable to access files in subfolders
Closed this issue · 7 comments
If I have a subfolder, inside the top folder as a webserver it should be able to pick things up, it doesn't. Has this been tested for scenarios other than the given one level directory structure.
# Declare route from a dict naw.routes = { '/api/status': api_status, }
This doesn't work - it doesn't check these routes at all
Please, put a complete example.
Thank you for responding, I have fixed it myself. regarding the subfolder folder - the trailing / in the assets_DIR declaration was causing some issues, so I have defined it like this which has resolved many of the problems
ASSETS_DIR = 'www'
IMAGE_DIR = 'www/images'
However I had to change this %s/%s - to %s%s or else I was getting a extra / before the file name. Now everything looks resolved. Except that when I use a SVG file - the file gets downloaded but it doesn't show up. But the browser opens the SVG file if I access the html page offline. Do you have any thoughts?
# 4. Current url have an assets extension ?
for extension in self.assets_extensions:
if request.url.endswith('.' + extension):
await send_file(
request,
**'%s%s' % (**
self.STATIC_DIR,
request.url,
),
binary=True,
)
You have to handle manually the header with a correct mimetype.
Another issue, I have bootstrap.min.css in the same folder as my html - html as below. The browser downloads the style sheet but is not able to render it, see attached screen shot - this shows the file has downloaded in 6 seconds (which itself is too long for 195K file) but if you see it has only a size of 115KB - there seems to be some data loss hence the style sheet has not been rendered.
This is the page rendered when accessed through your webserver - which is not loading the style sheet
This is the page when loaded directly from the hardrive (offline) see the bootstrap stylesheet file size
<!DOCTYPE html>
<html lang="en">
<head>
<title>Home1</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="styles.css" />
<link rel="stylesheet" href="bootstrap.min.css"/>
<script" src="js/bootstrap.bundle.min.js"/>
</head>
<body>
<div class="wrapper">
<div class="logo">
<img
src="images/testlogo.png"
alt=""
/>
</div>
<div class="text-center mt-4 name">Switch Board Login</div>
<form class="p-3 mt-3">
<div class="form-field d-flex align-items-center">
<input
type="password"
name="password"
id="pwd"
placeholder="Password"
/>
</div>
<button class="btn mt-3">Login</button>
</form>
</div>
</body>
</html>
I can't guess if you don't put a code example.
And it seems to be the same problem as for SVG: A mimetype problem.
FYI: throughput of large data transmission can be improved using segment
kwarg. The default value is 64. The upper bound varies up to the board/SoC you use.
Example:
await send_file(request, filename, segment=256)