Downloaded filename with Google App Engine Blobstore

后端 未结 4 2021
余生分开走
余生分开走 2021-02-14 10:52

I\'m using the Google App Engine Blobstore to store a range of file types (PDF, XLS, etc) and am trying to find a mechanism by which the original filename of the uploaded file -

4条回答
  •  失恋的感觉
    2021-02-14 11:07

    Another option is to append the file name to the end of the download URL. For example:

    /files/AMIfv95HJJY3F75v3lz2EeyvWIvGKxEcDagKtyDSgQSPWiMnE0C2iYTUxLZlFHs2XxnV_j1jdWmmKbSVwBj6lYT0-G_w5wENIdPKDULHqa8Q3E_uyeY1gFu02Iiw9xm523Rxk3LJnqHf9n8209t4sPEHhwVOKdDF2A/prezents-list.doc
    

    If you use Jinja2 for templating, you can construct such an URL like this:

    {{file.filename}}
    

    then you should adapt your URL mapping accordingly to something like this:

    ('/files/([^/]+)/?.*', DownloadHandler)
    

    If you have the blob key in the URL, you can ignore the file name in your server-side code.

    The benefit of this approach is that content types like images or PDF open directly in the browser, which is convenient for quick viewing. Other content types will just be saved to disk.

提交回复
热议问题