Skip to content

Commit ab40a43

Browse files
committed
download: setting the filename of the content of the file indices to their original value
1 parent 19e37eb commit ab40a43

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

cernopendata/modules/records/utils.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,28 @@
1919

2020
"""Implementention of various utility functions."""
2121

22+
import itertools
2223
import json
24+
import re
25+
import sys
26+
from os.path import basename
2327
from re import sub
24-
import six
25-
import itertools
2628

29+
import flask
30+
import six
2731
from flask import abort, current_app, jsonify, render_template, request
32+
from invenio_files_rest.models import FileInstance
2833
from invenio_files_rest.views import ObjectResource
2934
from invenio_records.api import Record
3035
from invenio_records_files.utils import record_file_factory
3136

32-
from invenio_files_rest.models import FileInstance
33-
3437
# from invenio_files_rest.models import FileInstance, ObjectVersion
3538
# from invenio_records.errors import MissingModelError
3639
from invenio_records_ui.utils import obj_or_import_string
37-
from invenio_xrootd import EOSFileStorage
38-
from werkzeug.utils import import_string
39-
4040
from invenio_search import current_search_client
4141
from invenio_search.engine import dsl, search
42-
43-
import sys
44-
import flask
45-
import re
42+
from invenio_xrootd import EOSFileStorage
43+
from werkzeug.utils import import_string
4644

4745

4846
def get_file_index(pid, record, file_index, **kwargs):
@@ -100,11 +98,14 @@ def file_download_ui(pid, record, _record_file_factory=None, **kwargs):
10098
obj = ObjectResource.get_object(
10199
file["bucket"], file["key"], file["version_id"]
102100
)
101+
# Let's overwrite the key of the object, so that the downloads has the same name
102+
# Note that the basename could not have been used as the key, since multiple files could
103+
# have the same basename inside a file index
104+
obj.key = basename(obj.file.uri)
103105
if not obj:
104106
abort(404)
105107
else:
106108
obj = fileobj.obj
107-
108109
# Check permissions
109110
ObjectResource.check_object_permission(obj)
110111

0 commit comments

Comments
 (0)