Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access files in subfolders #19

Closed
krishnak opened this issue Sep 8, 2022 · 7 comments
Closed

Unable to access files in subfolders #19

krishnak opened this issue Sep 8, 2022 · 7 comments

Comments

@krishnak
Copy link

krishnak commented Sep 8, 2022

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.

@krishnak
Copy link
Author

krishnak commented Sep 8, 2022

# Declare route from a dict naw.routes = { '/api/status': api_status, }

This doesn't work - it doesn't check these routes at all

@hugokernel
Copy link
Owner

Please, put a complete example.

@krishnak
Copy link
Author

krishnak commented Sep 8, 2022

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,
                                )

@hugokernel
Copy link
Owner

You have to handle manually the header with a correct mimetype.

@krishnak
Copy link
Author

krishnak commented Sep 8, 2022

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
image

This is the page when loaded directly from the hardrive (offline) see the bootstrap stylesheet file size

image

<!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>

@hugokernel
Copy link
Owner

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.

@puhitaku
Copy link
Contributor

puhitaku commented Sep 8, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants