0
AWSに画像をbase64文字列または画像としてアップロードしようとしていますが、アップロード後に画像が壊れたり黒くなったりします。PythonがAWSに画像をアップロードする - 画像が黒くなる/壊れてしまう
for item in os.listdir(os.path.join(app.config['UPLOAD_FOLDER'])):
if item.startswith(str(current_user.id)):
with open(os.path.join(app.config['UPLOAD_FOLDER'], item)) as thefile:
data = base64.b64encode(thefile.read())
upload_image_to_aws_from_image_v3('MYBUCKET', "userimg/", data, new_zimmer, "hauptbild", new_zimmer.stadt, new_zimmer.id)
AWSのための方法:
def upload_image_to_aws_from_image_v3(bucketname, bucketpath, image_from_form, model_to_change, model_column, model_addon_for_name, model_addon_for_name_id):
s3 = boto.connect_s3(app.config['MY_AWS_ID'], app.config['MY_AWS_SECRET'], host='s3.eu-central-1.amazonaws.com')
bucket_name = bucketname
bucket = s3.get_bucket(bucket_name)
k = Key(bucket)
#file_contents = image_from_form.read()
the_filename = "zimmer-" + model_addon_for_name.lower().strip() + str(model_addon_for_name_id) + ".jpg"
filename_hauptbild = secure_filename(the_filename)
k.key = bucketpath + filename_hauptbild
k.set_contents_from_string(image_from_form)
setattr(model_to_change, model_column, filename_hauptbild)