#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?)
{{url=URL(r=request,c='download',args=audio_filename)}}
<embed src="{{=url}} />
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
{{audio_filename='folder1/folder2/audio_filename.mp3'}}
{{url=URL(r=request,c='default',f='download',args=audio_filename)}}
<embed src="{{=url}} />
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.
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?