Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9191191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:37:34+00:00 2026-06-17T20:37:34+00:00

In my case i have a database with document thumbnails that are displayed on

  • 0

In my case i have a database with document thumbnails that are displayed on an overview page. Every time the browser visits the site all thumbnail images are downloaded again and so the download function loads again all the images from the database. Since i am running on GAE this drives up my database-reads enormous.

I tried to enable client site caching by setting:

@auth.requires_login()
def download():
  response.headers['Cache-Control'] = None
  response.headers['Pragma'] = None
  response.headers['Expires'] = None
  return response.download(request, db)

I also read that response.stream may help but the web2py book says:

As noted above, response.download should be used to retrieve files stored via an upload field. response.stream can be used in other cases, such as returning a temporary file or StringIO object created by the controller.

— EDIT —

I got the client side caching enabled with:

session.forget() #important
expire_time = datetime.timedelta(days=2)

response.headers['Cache-Control'] = 'private, max-age%d'%(60*60*24*2)
response.headers['Pragma'] = None
response.headers['Expires'] = (request.utcnow + expire_time).strftime("%a, %d %b %Y %H:%M:%S GMT")
response.headers['Content-Disposition'] = \
      'attachment;filename=' + filename + ';'

return response.stream(stream, filename=filename)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:37:35+00:00Added an answer on June 17, 2026 at 8:37 pm

    First, if the images are publicly available and do not require authentication to view, then instead of storing them in the /uploads folder, you can store them in the /static folder and then simply serve them as static files. In that case, the headers will be set automatically for client side caching (it will also be faster and more efficient).

    Second, you can use response.stream() to stream uploaded files, but it won’t automatically identify the folder where the file is located nor decode the original filename from the encoded filename and add it to the Content-Disposition header (which you don’t need in this case anyway because you are displaying the images and not downloading them). So, as long as you pass the full file path to response.stream(), you should be able to use it in this case, and it will set the response headers appropriately for caching.

    Finally, if you want to set the response headers directly, it would be something like:

    import os
    import time
    modified = os.stat(file)[stat.ST_MTIME]
    mtime = time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime(modified))
    response.headers['Last-Modified'] = mtime
    response.headers['Pragma'] = 'cache'
    response.headers['Cache-Control'] = 'private'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an html page that is displayed on a television screen sort of
I have written a xml/php document that is pulling from a Magento Commerce database,
I have a case sensitive SERVER (SQL_Latin1_General_CP1_CS_AS) but the Database is Case insensitive (SQL_Latin1_General_CP1_CI_AS).
I wonder a case. I have a project using a database (Oracle and Mssql).
I have a really interesting case: I have a site where this is already
In case I have .NET framework installed in my computer + all the necessary
I have a regular .NET application. In this case I have a part that's
I have a case statement that returns a date; case when (ma.first_active_date is not
I have created a program that runs off of an Access database on the
I have a marklogic (4.2) database that contains tens of thousands of large-ish, complex-ish

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.