diff --git a/gcsmigrate/enqueue.py b/gcsmigrate/enqueue.py index ba57969..db33aa1 100644 --- a/gcsmigrate/enqueue.py +++ b/gcsmigrate/enqueue.py @@ -137,6 +137,7 @@ def queue_lemur_final(buckets, state_db): sql = """ SELECT id, objects.objKey, + objects.downloadName, checksum FROM ( SELECT objKey, @@ -155,12 +156,13 @@ def queue_lemur_final(buckets, state_db): cursor.execute(sql, (bucket_id, initial_id, bucket_id)) row = cursor.fetchone() while row: - (crepo_file_id, obj_key, sha) = row + (crepo_file_id, obj_key, download_name, sha) = row to_key = f"{obj_key}" json = { "bucket": gcs_bucket_name, "from_key": sha, "to_key": to_key, + "download_name": download_name } yield CLIENT.publish(TOPIC_PATH, encode_json(json), action="copy") maybe_update_max(state_db, LATEST_CREPO_ID_KEY, crepo_file_id) diff --git a/gcsmigrate/main.py b/gcsmigrate/main.py index 1945022..c1e2574 100644 --- a/gcsmigrate/main.py +++ b/gcsmigrate/main.py @@ -34,6 +34,7 @@ def main(event, context): bucket_name = json_struct["bucket"] from_key = json_struct["from_key"] to_key = json_struct["to_key"] - copy_object(gcs_client, bucket_name, from_key, to_key) + download_name = json_struct.get("download_name") + copy_object(gcs_client, bucket_name, from_key, to_key, download_name) else: raise Exception(f"Bad action: {action}.") diff --git a/gcsmigrate/shared.py b/gcsmigrate/shared.py index 561e0b4..614c4ff 100644 --- a/gcsmigrate/shared.py +++ b/gcsmigrate/shared.py @@ -62,13 +62,15 @@ def make_db_connection(db_url): ) -def copy_object(gcs_client, bucket_name, from_key, to_key): +def copy_object(gcs_client, bucket_name, from_key, to_key, download_name=None): bucket = gcs_client.bucket(bucket_name) source_blob = bucket.blob(from_key) bucket.copy_blob(source_blob, bucket, to_key) mimetype = guess_mimetype(to_key) target_blob = bucket.blob(to_key) target_blob.content_type = mimetype + if download_name: + target_blob.content_disposition = f"filename=\"{download_name}\"" target_blob.patch()