why is "uploads" folder so special?

13 views
Skip to first unread message

weheh

unread,
Jan 7, 2010, 1:23:31 AM1/7/10
to web2py-users
I want to store an audio file in the uploads folder and then have it
played by an embed:

#view
{{url=os.path.join(request.folder,URL
(r=request,c='uploads',f='audio',args=[audio_filename])}}
<embed src="{{=url}} />

This won't work. Why not? (If I move everything over to the static
folder and then change 'uploads' to 'static' in the URL statement, it
does work. But it's more logical for me to store the audio in the
uploads folder. What's so special about uploads?)

weheh

unread,
Jan 7, 2010, 1:58:40 AM1/7/10
to web2py-users
I guess the os.path.join(request.folder...) isn't really necessary in
the above-given example. Just there as part of my testing why this
wasn't working.

Jason Brower

unread,
Jan 7, 2010, 4:09:29 AM1/7/10
to web...@googlegroups.com
Unless you uploaded it with your web app, I would put it in static.
Regards

mdipierro

unread,
Jan 7, 2010, 8:55:39 AM1/7/10
to web2py-users
It is not special. It is a folder. It is not a controller action. Here
is what you do:

{{url=URL(r=request,c='download',args=audio_filename)}}
<embed src="{{=url}} />

weheh

unread,
Jan 7, 2010, 5:22:59 PM1/7/10
to web2py-users
Sorry, Massimo, no joy.

What is my download controller supposed to look like and what folder
and file is it supposed to be in?

Currently, the view is called from controller "audio" and action
"index". audio.py has

def download():
return response.download(request,db)

I also tried making a controllers/download.py with a def index():
return response.download(request,db), but of course, that didn't work
either. Don't ask me why x|

Sorry, now I'm groping.

The audio is under
/app/uploads/folder1/folder2/audio_filename.mp3

mdipierro

unread,
Jan 7, 2010, 5:37:02 PM1/7/10
to web2py-users
Summing you have a download in controller default.py

{{audio_filename='folder1/folder2/audio_filename.mp3'}}
{{url=URL(r=request,c='default',f='download',args=audio_filename)}}
<embed src="{{=url}} />

mdipierro

unread,
Jan 7, 2010, 5:47:05 PM1/7/10
to web2py-users
ERRATA. This will not work. I overlooked the fact you put something
under uploads that is not actually uploaded and does not follow
appropriate naming convention.

You need:

1) your own action in controllers/audio.py

def download_audio():
f=os.path.join(request.folder,'uploads',request.args(0))
return response.stream(open(f,'rb'))

2) in view

{{audio_filename='folder1/folder2/audio_filename.mp3'}}
{{url=URL
(r=request,c='audio',f='download_audio',args=audio_filename)}}
<embed src="{{=url}} />

Anyway. This kind of stuff should go under 'private' not 'uploads'.
That is what private is for.

weheh

unread,
Jan 7, 2010, 7:53:32 PM1/7/10
to web2py-users
That's cool. I can put things under private. I didn't realize that was
supposed to be my play area.

If I do put files under private, should I insert the file's filename
into a db field of type string or should I use db.table.insert
(fieldname=db.table.fieldname.store(stream,'filename'))?

I know that in private I'm responsible for the contents of files. But
it seems valuable to have access to the built-in web2py security code
if I'm doing some magic on uploaded files, right? Is there a
documented way to access this code directly?

mdipierro

unread,
Jan 7, 2010, 7:58:14 PM1/7/10
to web2py-users
Under private should not use db.table.field.store and you should not
use dafult/download.
Reply all
Reply to author
Forward
0 new messages