Google App Engine sample application for downloading and serving arbitrary files

I would like to use GAE to allow multiple users to upload files and then extract them. Files will be relatively small (a few hundred KB), so you just need to store things like blob. I could not find examples of something like this. There are several examples of loading images, but I would like to be able to store text documents, pdfs, tiffs, etc. Any ideas / pointers / links? Thank!

+3
source share
3 answers

The same logic used to load images applies to other types of archives. To make the file downloadable, you add a header Content-Dispositionso that the user receives a request to download it. An example of a simple webapp:

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 :)

+3
source

It looks like you want to use the Blobstore API.
You do not mention whether you use Python or Java , so there are links to both here.

+2
source

I use the blobstore API, which allows upload / download of any file up to 50 MB.

+2
source

Source: https://habr.com/ru/post/1756119/


All Articles