2017-06-02 44 views
1

我想從Amazon保存S3中的圖像,我使用Pillow調整圖像大小。該圖片由用戶上傳,我將在調整大小後上傳。也就是說,它不存在於S3中。用django_storages將枕頭對象保存到S3

目前我做如下:

作爲枕頭的對象列表

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

回答

2

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