From 81bba9a631bde584e435e25ae2e88ebb9d5ac8d0 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Thu, 29 Feb 2024 22:37:42 +0000 Subject: [PATCH] Add --size-hint option --- ia-upload-stream | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ia-upload-stream b/ia-upload-stream index 35d372c..8a6e57c 100755 --- a/ia-upload-stream +++ b/ia-upload-stream @@ -215,7 +215,7 @@ def wait_first(tasks, parts): logger.info(f'Upload of part {partNumber} OK, ETag: {eTag}') -def upload(item, filename, metadata, *, iaConfigFile = None, partSize = 100*1024*1024, tries = 3, partTimeout = None, concurrency = 1, queueDerive = True, keepOldVersion = True, complete = True, uploadId = None, parts = None, progress = True): +def upload(item, filename, metadata, *, iaConfigFile = None, partSize = 100*1024*1024, tries = 3, partTimeout = None, concurrency = 1, queueDerive = True, keepOldVersion = True, complete = True, uploadId = None, parts = None, progress = True, sizeHint = None): f = sys.stdin.buffer # Read `ia` config @@ -225,6 +225,8 @@ def upload(item, filename, metadata, *, iaConfigFile = None, partSize = 100*1024 headers = {'Authorization': f'LOW {access}:{secret}'} metadataHeaders = metadata_to_headers(metadata) initialHeaders = {**headers, 'x-amz-auto-make-bucket': '1', **metadataHeaders} + if sizeHint: + initialHeaders['x-archive-size-hint'] = str(sizeHint) extraHeaders = {'x-archive-queue-derive': '1' if queueDerive else '0', 'x-archive-keep-old-version': '1' if keepOldVersion else '0'} # Always read the first part @@ -406,6 +408,7 @@ def main(): parser.add_argument('--concurrency', '--concurrent', type = int, default = 1, metavar = 'N', help = 'upload N parts in parallel (default: 1)') parser.add_argument('--no-complete', dest = 'complete', action = 'store_false', help = 'disable completing the upload when stdin is exhausted') parser.add_argument('--no-progress', dest = 'progress', action = 'store_false', help = 'disable progress bar') + parser.add_argument('--size-hint', dest = 'sizeHint', type = size, help = "size hint for the total item size; only has an effect if the item doesn't exist yet") parser.add_argument('--upload-id', dest = 'uploadId', help = 'upload ID when resuming or aborting an upload') parser.add_argument('--parts', type = parts, help = 'previous parts data for resumption; can only be used with --upload-id') parser.add_argument('--abort', action = 'store_true', help = 'aborts an upload; can only be used with --upload-id; most other options are ignored when this is used') @@ -441,6 +444,7 @@ def main(): uploadId = args.uploadId, parts = args.parts, progress = args.progress, + sizeHint = args.sizeHint, ) elif args.list: list_uploads(args.item, tries = args.tries)