0

I want to send an image in an s3 storage (MinIO).

Here is an example code :

import cv2
import argparse
import boto3
from botocore.client import Config
import logging

logging.basicConfig(level=logging.INFO)

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--s3_endpoint', type=str, default='http://127.0.0.1:9000')
parser.add_argument('--s3_access_key', type=str,default='minioadmin')
parser.add_argument('--s3_secret_key', type=str,default='minioadmin')
parser.add_argument('--image_bucket', type=str,default='my_bucket')
args = parser.parse_args()

s3 = boto3.client(
    "s3",
    use_ssl=False,
    endpoint_url=args.s3_endpoint,
    aws_access_key_id=args.s3_access_key,
    aws_secret_access_key=args.s3_secret_key,
    region_name='us-east-1',
    config=Config(s3={'addressing_style': 'path'})
)

def upload_image_s3(bucket, image_name, image):
    logging.info("Uploading image "+image_name+" to s3 bucket "+bucket)
    body = cv2.imencode('.jpg', image)[1].tostring()
    s3.put_object(Bucket=bucket, Key = image_name, Body = body)
    logging.info("Image uploaded !")

upload_image_s3(args.processed_images_bucket,'test/image.jpg',cv2.imread("resources/images/my_image.jpg"))

But when I run it, I get stuck on the put_object() call forever (well, until timeout to be exact).

To do my test, I run locally a minIO server using the default configuration (on Windows).

Have you any idea what is the problem in my case ?

Nakeuh
  • 1,757
  • 3
  • 26
  • 65
  • 1
    https://docs.min.io/docs/how-to-use-aws-sdk-for-python-with-minio-server.html suggests a different set of arguments to `boto.client()` – Alastair McCormack Mar 17 '20 at 10:40
  • Hm, I don't know exactly why, but replacing `http://127.0.0.1:9000` by `http://localhost:9000`, as in the doc solved my problem. I think I'll remove this question. – Nakeuh Mar 17 '20 at 10:46

1 Answers1

0

I was having the same error, my mistake was incorrect credentials when I want to connect with minIO. When I see that you just change the host to localhost I review all the code and realized that it was just a typo in my credentials