login community faq

Hi guys,
In a site I'm writing, I'm allowing users to upload arbitrary files (part of a syncing service) to my site. The local Javascript client has to be able download via Ajax the files from the server running Python+Django. The user also has the ability to "export" files and directories by visiting a page which would send the Content-Disposition: attachment header and allow them to download the file/directory.

The problem is that any given file or directory isn't necessarily supposed to be public to other users. My concern is really memory constraints -- outputting each file via Python in the following fashion probably isn't very memory efficient, whereas Apache is probably very efficient. However, I can't directly perform any auth with Apache

    # Example code:
    response = HttpResponse()
    file = open("/path/to/users/file.html", "r")
    for line in file:
        response.write(line)
    return response
    

I figure I have two options here, since these are all going to be static files:

  1. The files would be outputted by Apache. Each user would have a random url to which everything would be uploaded, and a request to download the file would redirect to the file path underneath the user's random url. The seems like it isn't super-secure and is kind of a mess.
  2. The url would be the path to a Django request handler which would validate the the user's ability to download the file, and output via the code above. I don't think this is very memory-efficient though

Am I wrong in thinking that the above is not memory-efficient? Which would you guys go with?

(I know this is kinda of a long post. Sorry about that, and thanks in advance)

asked May 28 '11 at 19:58

jordonwii's gravatar image

jordonwii
12


Personally, I think the correct approach is to serve the files separately and not directly from the Django application. The problem, as you stated, is that you just need authentication on those downloads. You should be able to do that using mod_xsendfile for apache, as discussed in this related topic:

http://community.webfaction.com/questions/1066/installing-mod_xsendfile-on-django-apache-instance

answered May 28 '11 at 20:20

ryans's gravatar image

ryans ♦♦
28411420

edited May 28 '11 at 20:20

Ah, that looks perfect. Thanks. I'm going to look into that.

(May 28 '11 at 22:34) jordonwii jordonwii's gravatar image
Your answer
If you have an answer to the above question, then use the form below. Otherwise, use the appropriate 'add new comment' button above to post your feedback.
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×643
×229
×57

Asked: May 28 '11 at 19:58

Seen: 1,420 times

Last updated: May 28 '11 at 22:34

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited