简体   繁体   English

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

[英]Save pillow objects to S3 with django_storages

I want to save in S3 from Amazon an image that I resize with Pillow. 我想从Amazon保存S3中使用Pillow调整大小的图像。 That image is uploaded by the user and I will upload it once resized. 该图像由用户上传,调整大小后我将上传。 That is, it does not exist in S3. 也就是说,它在S3中不存在。

Currently I'm doing it as follows: 目前,我正在执行以下操作:

Being a list of Pillow objects 成为枕头对象列表

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

You can use boto3 to upload files to s3. 您可以使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM