views:

52

answers:

3

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
Thanks! Exactly what I needed!
Swingley
+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
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