Skip to content

Commit

Permalink
[FIX] fs_attachment: respect controller parameters for /web/content/
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn authored and OCA-git-bot committed May 6, 2024
1 parent 9ac33dd commit 8d52fb0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
28 changes: 28 additions & 0 deletions fs_attachment/models/ir_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ def _record_to_stream(self, record, field_name):
return FsStream.from_fs_attachment(fs_attachment)
return super()._record_to_stream(record, field_name)

def _get_stream_from(
self,
record,
field_name="raw",
filename=None,
filename_field="name",
mimetype=None,
default_mimetype="application/octet-stream",
):
stream = super()._get_stream_from(
record,
field_name=field_name,
filename=filename,
filename_field=filename_field,
mimetype=mimetype,
default_mimetype=default_mimetype,
)

if stream.type == "fs":
if mimetype:
stream.mimetype = mimetype
if filename:
stream.download_name = filename
elif record and filename_field in record:
stream.download_name = record[filename_field] or stream.download_name

return stream

def _get_image_stream_from(
self,
record,
Expand Down
11 changes: 11 additions & 0 deletions fs_attachment/tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ def test_content_url(self):
},
assert_content=self.content,
)
url = f"/web/content/{self.attachment_binary.id}/?filename=test2.txt&mimetype=text/csv"
self.assertDownload(
url,
headers={},
assert_status_code=200,
assert_headers={
"Content-Type": "text/csv; charset=utf-8",
"Content-Disposition": "inline; filename=test2.txt",
},
assert_content=self.content,
)

def test_image_url(self):
self.authenticate("admin", "admin")
Expand Down

0 comments on commit 8d52fb0

Please sign in to comment.