【问题标题】:Save pillow objects to S3 with django_storages使用 django 存储将枕头对象保存到 S3
【发布时间】:2017-06-02 09:48:31
【问题描述】:

我想从 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")

【问题讨论】:

    标签: python django amazon-s3 amazon pillow


    【解决方案1】:

    您可以使用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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-06
      • 2022-01-07
      • 1970-01-01
      • 2020-11-09
      • 2012-01-05
      • 2015-06-05
      • 2015-05-16
      • 1970-01-01
      相关资源
      最近更新 更多