Last active
April 8, 2022 15:40
-
-
Save UnknownPlatypus/3435bcba6d31f3ece88c762cceb62b85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
headers = { | |
'Cache-Control':'max-age=604800', # 60 x 60 x 24 x 7 = 1 week | |
'Content-Type':content_type, | |
} | |
k = Key(self.get_bucket()) | |
k.key = filename | |
k.set_contents_from_string(contents.getvalue(), headers) | |
if self.public: k.make_public() | |
for key in bucket.list(): | |
print key.name.encode('utf-8') | |
metadata = key.metadata | |
metadata['Cache-Control'] = 'max-age=604800' # 60 x 60 x 24 x 7 = 1 week | |
key.copy(AWS_BUCKET, key, metadata=metadata, preserve_acl=True) | |
##############################"""" | |
import boto3 | |
from django.conf import settings | |
s3 = boto3.resource('s3') | |
s3client = boto3.client('s3') | |
# List keys | |
bucket = s3.Bucket(settings.AWS_STORAGE_BUCKET_NAME) | |
keys = [b.key for b in bucket.objects.filter(Prefix='media/blog/pictures/')] | |
# Get metadata for one key | |
s3client.head_object(Bucket=bucket.name, Key=keys[0]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment