python - 使用 django_storages 将枕头对象保存到 S3

标签 python django amazon-web-services amazon-s3 python-imaging-library

我想在 Amazon S3 中保存一张使用 Pillow 调整大小的图像。该图像是由用户上传的,调整大小后我将上传它。即S3中不存在。

目前我正在这样做:

作为 Pillow 对象的列表

def upload_s3(files):
    for f in files:
        print(f)
        path = default_storage.save('/test/cualquiersa/')
        f.save(path, "png")

最佳答案

您可以使用boto3将文件上传到s3。

import boto3

client = boto3.client('s3')
# For more client configuration http://boto3.readthedocs.io/en/latest/

def upload_s3(files):
for f in files:
    print(f)
    response = client.put_object(
        Body= f,
        Bucket=<bucket_name>,
        Key=<location/directory>
    )
# More code here

关于python - 使用 django_storages 将枕头对象保存到 S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44325865/

相关文章:

python - Python中命名空间对象的含义

python - 使用三次样条在 Pandas 中插值时间序列

python - 在 python 中使用 opencv 剪切图像的特定部分

python - Django:对象不可迭代

database - django fixtures 是可靠的数据库备份吗?

python - 为什么 seaborn Heatmap 显示白色的行和列?

django - 如何在 python django 中使用一些匹配的字母而不是完全匹配来过滤查询结果?

amazon-web-services - AWS Lambda 函数的库存储在哪里?

amazon-web-services - 使用自签名证书验证复制从属服务器上的主机身份

amazon-web-services - AWS lambda list-functions仅过滤出函数名称?