updated that one line to this, but it's not any better, just slightly more portable. Any insights?
return open("./applications/" + request.application + "/uploads/" + rows[0].filedata).read() On Apr 16, 12:49 pm, Dragonfyre13 <dragonfyr...@gmail.com> wrote: > I want to be able to stream a file that's uploaded via an upload > field. So far, I haven't really found a way to do this, beyond > grabbing the file name out of filedata, and then sticking static > directory path on the front, which is both kludgy, and I have to think > the wrong way of going about it. Here's what I've got: > > def play(): > response.headers["Content-Type"] = "audio/x-vox" > response.headers["Content-Disposition"] = "attachment; filename=" > + request.args[0] + '.vox' > rows = db(db.audio_files.playname == > request.args[0]).select(db.audio_files.ALL) > if len(rows): > return open("/opt/web2py/applications/myapp/uploads/" + > rows[0].filedata).read() > else: > raise ValueError, "Passed incorrect playname: " + > str(request.args[0]) > > Essentially, I have another controller uploading to the DB under > audio_files, and sticking a "playname" in the database as a reference > to that file. I can then pass the "playfile" name into this function > in order to get it to return the data out of that file handed back. > > Here's the problem. Right now, I've got the directory path prepended > statically. That's bad in a big way. Second, there's no sanitation, > and minimal error handling. That will be cleaned up once I get it > working with an actual solution, rather than this hackish thing. > > Basically, I expect that there's something other than > response.download that will give me the actual data for a file. I > tried response.download, but it doesn't let me set the content-type, > or content-disposition (that's all set by it, overriding my header > info). There has to be something that says "take the data from this > database entry, as a file object", I'm just looking for what that is. > > I then want to be able to store back into it, but that's another point > not covered above, and I would assume I can just overwrite the old > file data, or just update the field in the DB. Perhaps if someone is > tackling the previous question, they can give this one a go too? > > -- > Subscription settings:http://groups.google.com/group/web2py/subscribe?hl=en