Skip to content

Commit 6ced241

Browse files
authored
Merge pull request #264 from OpenTreeOfLife/force-collection-download
Force collection download to JSON file
2 parents 22db231 + fdce137 commit 6ced241

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

phylesystem_api/phylesystem_api/views/collection.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ def is_valid_collection_id(doc_id):
6868
def fetch_collection(request):
6969
# NB - This method does not require authentication!
7070
collection_id = request.matchdict["collection_id"]
71+
72+
# if '.json' was added to the URL, specify as download
73+
if collection_id.endswith('.json'):
74+
# save this as a filename WITHOUT slashes
75+
preferred_filename = collection_id.replace('/','_')
76+
# ADD content-disposition header
77+
response = request.response
78+
response.headers["Content-Disposition"] = "attachment; filename={};".format(preferred_filename)
79+
collection_id = collection_id[0:-5] # trim the '.json' extension and proceed w/ fetch
80+
7181
result = fetch_doc(
7282
request,
7383
doc_id=collection_id,

0 commit comments

Comments
 (0)