Skip to content

Commit 9b7a170

Browse files
authored
Merge pull request #251 from linode/bugfix/image-uplaod-check-max-upload-size
fix: Check Image upload size before attempting upload
2 parents b212eef + 5acaf20 commit 9b7a170

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

linodecli/plugins/image-upload.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from sys import exit
1313

1414
PLUGIN_BASE = 'linode-cli image-upload'
15+
MAX_UPLOAD_SIZE = 5 * 1024 * 1024 * 1024 # 5GB
1516

1617

1718
def _progress(cur, total):
@@ -83,17 +84,22 @@ def call(args, context):
8384
# get default region populated
8485
context.client.config.update(parsed)
8586

86-
if not parsed.region:
87-
print("No region provided. Please set a default region or use --region")
88-
exit(1)
89-
9087
# make sure the file exists and is ready to upload
9188
filepath = os.path.expanduser(parsed.file)
9289

9390
if not os.path.isfile(filepath):
9491
print("No file at {}; must be a path to a valid file.".format(filepath))
9592
exit(2)
9693

94+
# make sure it's not larger than the max upload size
95+
if os.path.getsize(filepath) > MAX_UPLOAD_SIZE:
96+
print("File {} is too large; compressed size must be less than 5GB".format(filepath))
97+
exit(2)
98+
99+
if not parsed.region:
100+
print("No region provided. Please set a default region or use --region")
101+
exit(1)
102+
97103
label = parsed.label or os.path.basename(filepath)
98104

99105
# generate an upload URL

0 commit comments

Comments
 (0)