Fix upload_attachments: specify file name in parameter dict#15
Fix upload_attachments: specify file name in parameter dict#15raph-topo wants to merge 1 commit intoricpol:mainfrom
upload_attachments: specify file name in parameter dict#15Conversation
Rationale: path on disk may not exist or may not be significant (as with `NamedTemporaryFile()`).
|
Non sure about this - a NamedTemporaryFile is just a file that happens to be managed by tempfile... but you may still get its path with "f.name". or - maybe I didn't understand what you are trying to do here? What use case do you have in mind? |
Yes, a random name, which it makes no sense to store in Grist. (But Pygrister
I'm using my pygrister fork including this PR to copy attachments from one Grist doc to another, without loosing their name: ...
for att in fr.attachments:
with NamedTemporaryFile() as file:
fr.grist.download_attachment(
filename=Path(file.name),
attachment_id=att.id,
)
to_id: int = to.grist.upload_attachments(
{att.fields.fileName: Path(file.name)}
)[1][0]
...(
|
|
Oh, I see the point now, but your specific use case seem a little too fringe to me... Basically, you are corrupting the file names at download time, then you want to restore them when uploading... But you are only saving a single "os.remove" call which should be enough to clean up your unwanted temporary files... That said, it is true that Pygrister allows for changing the file name only at download time, and not when uploading, which is rather odd... Righ now I'm +0 about this change but I'll take a closer look and see if there are any drawbacks... |
That's true in the described scenario indeed. But one could also imagine a scenario where the script also changes the name based on some other properties.
Indeed. Though Python code style is pushing towards less |
Rationale: path on disk may not exist or may not be significant (as with
NamedTemporaryFile()).