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

  • SEARCH
  • Home
  • 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 6144637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:40:44+00:00 2026-05-23T18:40:44+00:00

I have a set of static files (that get uploaded through the application) like

  • 0

I have a set of static files (that get uploaded through the application) like images, video, etc. that need to be served to authenticated users (i.e. their cookie is registered as authenticated in the session).

These files are separate and in no way related to other media static files like css, javaacript, etc.

Given that my static files that need to be authenticated will be fairly large, I was wondering what would be the most efficient way of serving them (btw, i’m using wsgi).

Currently I have this:

def return_large_file(request, p_filename):
    """                                                                         
    Send a file through Django without loading the whole file into              
    memory at once. The FileWrapper will turn the file object into an           
    iterator for chunks of 8KB.                                                 
    """
    if not os.path.exists(p_filename):
        raise Exception('File %s does not exist!')

    try:
        _content_type = mimetypes.guess_type(p_filename)
    except:
        _content_type = 'application/octet-stream'

    wrapper = FileWrapper(file(p_filename))
    response = HttpResponse(wrapper, content_type=_content_type)
    response['Content-Length'] = os.path.getsize(p_filename)
    return response
  • 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-05-23T18:40:45+00:00Added an answer on May 23, 2026 at 6:40 pm

    I’m currently using a function similar to what you use above.

    I was thinking once performance/efficiency became an issue, I would use Apache mod-auth-external to do my custom authorization for a given file.

    Please note, I offer this answer not based on my experience, but where my own research led me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set up a Django application that uses images. I think I have
I have a Java application that parses pdf files in a directory and its
I have an express app that has a bunch of static javascript files that
I have set break points on my attached properties SetXXX and GetXXX static methods.
I have the following code: private static final Set<String> allowedParameters; static { Set<String> tmpSet
I have an Xcode project with several static library dependancies set up in the
I have a static variable partner in the class. And I want to set
We have set up a system where notifications get sent to a user with
I have written a method that downloads some files, and now I'm trying to
I have got folder binaries in my web application. I would like to download

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.