Hey Pylons people,
I'm trying to add file upload functionality to a Pylons project and
I'm following the Pylons Book example in chapter 6. Uploading the
file to a subdirectory ('uploads') of the data directory works fine.
Following the example, I set the permanent_store variable in
development.ini as:
permanent_store = %(here)s/data/uploads
and reference it in my create() action as:
config['app_conf']['permanent_store']
The problem arises when I want to reference my newly uploaded file in
a Mako template html <img> or <a> tag. If I use the value of
permanent_store as set in the config file, I get an absolute path and
that results in a 404 File Not Found error. That is, if I enter
<%! from os import sep, path %>
<% pathName = os.path.join(config['app_conf']['permanent_store'],
file.name) %>
<img src="${pathName}" />
the output is:
<img src="/home/MyApp/myapp/data/uploads/filename.png" />
which generates a 404 File Not Found error.
My solution is to move my uploads directory to the public directory,
i.e., by changing the line in the config file to:
permanent_store = %(here)s/myapp/public/uploads
and change my template code to:
<%! from os import sep, path %>
<% pathName = path.join(sep + config['app_conf']
['permanent_store'].split(sep)[-1], file.name) %>
<img src="${pathName}" />
This works. But I'm wondering whether I should be storing my user-
uploaded files in a subdirectory of the data directory for some
reason. And if I should be, how can I reference those files from my
Mako templates?
I remember from previous projects using PHP & Apache that storing
files in a subdirectory of public_html would render the files publicly
available. Access to my site will require authentication and I do not
want the files to be publicly accessible. Do I have to worry about
this if my uploaded files are stored in public/uploads?
Any help much appreciated,
Joel
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.