From 397ed5653b27a70538007980a739717b3450cd06 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 26 Sep 2025 21:35:00 +0000 Subject: [PATCH] overwrite on upload with header "replace" --- copyparty/httpcli.py | 8 ++++++-- docs/devnotes.md | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index a926948d..d18be57f 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -2301,7 +2301,11 @@ class HttpCli(object): if ( self.can_delete - and (vfs.flags.get("daw") or "x-oc-mtime" in self.headers) + and ( + vfs.flags.get("daw") + or "replace" in self.headers + or "x-oc-mtime" in self.headers + ) ) or ( not bos.path.exists(os.path.join(fdir, tnam)) and not bos.path.getsize(path) @@ -3344,7 +3348,7 @@ class HttpCli(object): open_args = {"fdir": fdir, "suffix": suffix, "vf": vfs.flags} - if "replace" in self.uparam: + if "replace" in self.uparam or "replace" in self.headers: if not self.can_delete: self.log("user not allowed to overwrite with ?replace") elif bos.path.exists(abspath): diff --git a/docs/devnotes.md b/docs/devnotes.md index 931c0ca8..fce97e1f 100644 --- a/docs/devnotes.md +++ b/docs/devnotes.md @@ -246,6 +246,7 @@ upload modifiers: | `Accept: json` | `want=json` | return upload info as json; same as `?j` | | `Rand: 4` | `rand=4` | generate random filename with 4 characters | | `Life: 30` | `life=30` | delete file after 30 seconds | +| `Replace: 1` | `replace` | overwrite file if exists | | `CK: no` | `ck` | disable serverside checksum (maybe faster) | | `CK: md5` | `ck=md5` | return md5 checksum instead of sha512 | | `CK: sha1` | `ck=sha1` | return sha1 checksum | @@ -254,7 +255,9 @@ upload modifiers: | `CK: b2s` | `ck=b2s` | return blake2s checksum | * `life` only has an effect if the volume has a lifetime, and the volume lifetime must be greater than the file's - +* `replace` upload-modifier: + * the header `replace: 1` works for both PUT and multipart-post + * the url-param `replace` only works for multipart-post * server behavior of `msg` can be reconfigured with `--urlform` ## admin