In my Python Appengine 'app' I have been asked to 'attach any file' so I have the following code snippet to 'display' those files...
blobattach = ''
blobmime = 'None'
if pattachment.blobkey <> None:
blobattach = get_serving_url(pattachment.blobkey) # <-- line 104
blob_info = blobstore.BlobInfo.get(pattachment.blobkey)
blobmime = blob_info.content_type[:5]
blobname = blob_info.filename
Using the following HTML
{% if blobmime == 'None' %}
{% else %}
{% if blobmime == 'image' %}
<img src="{{ blobattach }}" alt='Attachment'/>
{% else %}
<br/>
<small><a class="fswideb" href="{{blobattach}}" Title="Download to view"><span>Download to view {{ blobname }}</span></a></small>
{% endif %}
{% endif %}
If the attachment is an image, it is displayed (blobmime=='image'). If not, a link is displayed so the user can download the file and view it however they can.
However, while this works in development, on my laptop (Google App Engine Launcher), I get the following error when trying to 'serve' a .xls file. (No error with .jpg attachments)
File "/base/data/home/apps/s~fs-rentals/20140101.382312463312950329/fmntjobattachmaint.py", line 104, in display
blobattach = get_serving_url(pattachment.blobkey)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/images/__init__.py", line 1794, in get_serving_url
return rpc.get_result()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 613, in get_result
return self.__get_result_hook(self)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/images/__init__.py", line 1892, in get_serving_url_hook
raise _ToImagesError(e, readable_blob_key)
TransformationError
All of the examples use images and I have no problems with them, indeed no problems in development. Any thoughts on what I could have missed?
Many thanks David
As suggested I changed the above to use Google Cloud Storage. I still get exactly the same error. The get_serving_url function errors if the blob is not an image. Is there an equivalent for a file that is not an image?
The sample at https://cloud.google.com/appengine/docs/python/tools/webapp/blobstorehandlers#BlobstoreUploadHandler provides a really good example of what I am trying to do except that I may want to add the person's CV instead of their photo.
Thanks David