Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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