Skip to content

Commit

Permalink
Merge pull request #264 from OpenTreeOfLife/force-collection-download
Browse files Browse the repository at this point in the history
Force collection download to JSON file
  • Loading branch information
snacktavish authored Mar 5, 2024
2 parents 22db231 + fdce137 commit 6ced241
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions phylesystem_api/phylesystem_api/views/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ def is_valid_collection_id(doc_id):
def fetch_collection(request):
# NB - This method does not require authentication!
collection_id = request.matchdict["collection_id"]

# if '.json' was added to the URL, specify as download
if collection_id.endswith('.json'):
# save this as a filename WITHOUT slashes
preferred_filename = collection_id.replace('/','_')
# ADD content-disposition header
response = request.response
response.headers["Content-Disposition"] = "attachment; filename={};".format(preferred_filename)
collection_id = collection_id[0:-5] # trim the '.json' extension and proceed w/ fetch

result = fetch_doc(
request,
doc_id=collection_id,
Expand Down

0 comments on commit 6ced241

Please sign in to comment.