AWS S3优点:
AWS S3缺点:
Cassandra优点:
Cassandra缺点:
以下是使用AWS S3存储图像的Python代码示例:
import boto3 bucket_name = 'my-image-bucket' s3 = boto3.resource('s3') def upload_to_s3(file_path, key): s3.Object(bucket_name, key).put(Body=open(file_path, 'rb')) def download_from_s3(key, file_path): s3.Object(bucket_name, key).download_file(file_path)
以下是使用Cassandra存储图像的Python代码示例:
from cassandra.cluster import Cluster keyspace_name = 'my_keyspace' table_name = 'my_image_table' cluster = Cluster(['127.0.0.1']) session = cluster.connect(keyspace_name) def create_table(): session.execute(f"CREATE TABLE IF NOT EXISTS {table_name} (id uuid PRIMARY KEY, image blob);") def insert_image(image_id, file_path): with open(file_path, 'rb') as f: file_data = f.read() session.execute(f"INSERT INTO {table_name} (id, image) VALUES (%s, %s)", (image_id, bytes(file