0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ローカルでMD5つけてからAWSコンソールでアップしてみる

Posted at
import json
import hashlib

def calculate_md5(file_path):
    """ファイルのMD5ハッシュを計算する"""
    hash_md5 = hashlib.md5()
    with open(file_path, "rb") as f:
        for chunk in iter(lambda: f.read(4096), b""):
            hash_md5.update(chunk)
    return hash_md5.hexdigest()

def add_md5_to_json(json_file_path, md5_value):
    """JSONファイルにMD5ハッシュ値を追加する"""
    with open(json_file_path, 'r') as f:
        data = json.load(f)
    
    data["x-amz-meta-md5"] = md5_value
    
    with open(json_file_path, 'w') as f:
        json.dump(data, f, indent=4)

# ファイルのパス
file_path = 'path/to/your/file'
json_file_path = 'path/to/your/jsonfile.json'

# MD5ハッシュ値を計算
md5_value = calculate_md5(file_path)

# JSONファイルにMD5ハッシュ値を追加
add_md5_to_json(json_file_path, md5_value)

print(f"MD5 hash {md5_value} added to JSON file.")
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?