overwrite on upload with header "replace"

This commit is contained in:
ed 2025-09-26 21:35:00 +00:00
parent 9f46e4dbd7
commit 397ed5653b
2 changed files with 10 additions and 3 deletions

View file

@ -2301,7 +2301,11 @@ class HttpCli(object):
if ( if (
self.can_delete 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 ( ) or (
not bos.path.exists(os.path.join(fdir, tnam)) not bos.path.exists(os.path.join(fdir, tnam))
and not bos.path.getsize(path) and not bos.path.getsize(path)
@ -3344,7 +3348,7 @@ class HttpCli(object):
open_args = {"fdir": fdir, "suffix": suffix, "vf": vfs.flags} 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: if not self.can_delete:
self.log("user not allowed to overwrite with ?replace") self.log("user not allowed to overwrite with ?replace")
elif bos.path.exists(abspath): elif bos.path.exists(abspath):

View file

@ -246,6 +246,7 @@ upload modifiers:
| `Accept: json` | `want=json` | return upload info as json; same as `?j` | | `Accept: json` | `want=json` | return upload info as json; same as `?j` |
| `Rand: 4` | `rand=4` | generate random filename with 4 characters | | `Rand: 4` | `rand=4` | generate random filename with 4 characters |
| `Life: 30` | `life=30` | delete file after 30 seconds | | `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: no` | `ck` | disable serverside checksum (maybe faster) |
| `CK: md5` | `ck=md5` | return md5 checksum instead of sha512 | | `CK: md5` | `ck=md5` | return md5 checksum instead of sha512 |
| `CK: sha1` | `ck=sha1` | return sha1 checksum | | `CK: sha1` | `ck=sha1` | return sha1 checksum |
@ -254,7 +255,9 @@ upload modifiers:
| `CK: b2s` | `ck=b2s` | return blake2s checksum | | `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 * `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` * server behavior of `msg` can be reconfigured with `--urlform`
## admin ## admin