mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-04 22:41:12 +02:00
Fixed an issue with the server causing errors when uploading large images + Preparation for a smarter check when uploading images
This commit is contained in:
1 parent
19503ab4f7
commit
99e3529c93
2 files changed
+12
-1
No files matched your search
@@ -154,6 +154,17 @@ async def upload_image(
|
||||
if os.path.commonprefix([base_images_directory, full_path]) != base_images_directory:
|
||||
raise ControllerForbiddenError(f"Cannot write image, '{image_path}' is forbidden")
|
||||
|
||||
# If the client sends X-MD5-Checksum, check for a duplicate before consuming the upload stream
|
||||
checksum_header = request.headers.get("X-MD5-Checksum")
|
||||
if checksum_header:
|
||||
check_dir = os.path.dirname(full_path) if image_dir else None
|
||||
duplicate = await images_repo.get_image_by_checksum(checksum_header, check_dir)
|
||||
if duplicate:
|
||||
location = f" in '{check_dir}'" if check_dir else ""
|
||||
raise ControllerError(
|
||||
f"Image '{duplicate.filename}' with the same checksum already exists{location}"
|
||||
)
|
||||
|
||||
try:
|
||||
allow_raw_image = Config.instance().settings.Server.allow_raw_images
|
||||
image = await write_image(image_path, full_path, request.stream(), images_repo, allow_raw_image=allow_raw_image)
|
||||
|
||||
Reference in new issue
Block a user