I'd like to use GAE to allow a few users to upload files and later retrieve them. Files will be relatively small (a few hundred KB), so just storing stuff as a blob should work. I haven't been able to find any examples of something like this. There are a few image uploading examples out there but I'd like to be able to store word documents, pdfs, tiffs, etc. Any ideas/pointers/links? Thanks!
+1
A:
The same logic used for image uploads apply for other archive types. To make the file downloadable, you add a Content-Disposition
header so the user is prompted to download it. A webapp simple example:
class DownloadHandler(webapp.RequestHandler):
def get(self, file_id):
# Files is a model.
f = Files.get_by_id(file_id)
if not f:
return self.error(404)
# Set headers to prompt for download.
headers = self.response.headers
headers['Content-Type'] = f.content_type or 'application/octet-stream'
headers['Content-Disposition'] = 'attachment; filename="%s"' % f.filename
# Add the file contents to the response.
self.response.out.write(f.contents)
(untested code, but you get the idea :)
moraes
2010-07-23 07:19:18
Thanks! Exactly what I needed!
Swingley
2010-07-24 04:02:34
+1
A:
It sounds like you want to use the Blobstore API.
You don't mention if you are using Python or Java so here are links to both.
Peter Recore
2010-07-23 17:10:03
A:
I use blobstore API code linked above to similar project admitting any file upload/download up to 50 MB you may look if you like
LarsOn
2010-07-23 19:59:58