简体   繁体   中英

How can I include a numpy.ndarray as Metadata with boto3?

I would like to include a 2096 byte numpy array as metadata to an image that I'm uploading to S3

My upload code for boto3 is:

s3_response = s3.put_object(
                    Body=img,
                    Bucket='mybucket',
                    Key='test',
                    Metadata={
                        'f_vector': frame.f_vector
                    }

Where frame.f_vector is an numpy.ndarray

When doing this, I get AttributeError: 'numpy.ndarray' object has no attribute 'encode'

I have tried converting it to a list with f_vector.tolist() but then I just get AttributeError: 'list' object has no attribute 'encode' again

How can I send this img into S3 with a numpy array (or some medium format that I can convert back into a numpy array) as metadata?

Welp, looks like boto3 only allows strings as metadata, so you'd have to use numpy.array2string(x)

Unfortunately i found out that the maximum metadata size for S3 is 2kb, meaning that a (256,1) array is too big!

As a string it turned out to be 3135 bytes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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