atlassian-python-api
atlassian-python-api copied to clipboard
[confluence] attach_file should not have to read the whole file into RAM. Right?
In the attach_file
method,
with open(filename, "rb") as infile:
content = infile.read()
return self.attach_content(
content,
name,
content_type,
page_id=page_id,
title=title,
space=space,
comment=comment,
)
Is there some reason that should not be
with open(filename, "rb") as infile:
return self.attach_content(
infile,
name,
content_type,
page_id=page_id,
title=title,
space=space,
comment=comment,
)
instead?
Yes, the content must be a binary string and not a file handle.
From what I can determine, it actually doesn't. I examined the code, and that argument is passed to requests which wants a file-like object. It is actually not obvious to me, in reading the requests docs that a Bytes
object would work (though it obviously does).
I tested the change as written in my original post, and it is working for me.
When you get a chance, please look into this. I believe you will find that it is fine (and best) to pass the file object instead of reading the file in and then passing the Bytes
.
…or I can simply submit an MR if test coverage is in place to confirm that the change works.
The open
was there since the introduction of attach_file
. Feel free to create a PR.
The open
is needed. It's the read
that's not needed.
I mean the whole block.
@stevecj I will be happy if you submit MR/PR :)