pythonamazon-s3boto3numpy-stl

How to get .stl file from Amazon S3 by using boto3?


I have a Django Web application and i deployed it to Elastic Beanstalk environment. I also have the numpy-stl package. I'm trying to get a .stl file from Amazon S3 bucket and use this file with a stl package's function but i'm getting an error such as 'bytes' object has no attribute 'get_mass_properties'.

My code is;

s3 = boto3.client('s3')
obj = s3.get_object(Bucket=bucket_name, Key=key)
body = obj['Body'].read()
volume, cog, inertia = body.get_mass_properties()

How can i get the .stl file and use it?


Solution

  • I have fixed such as below.

    import stl
    import boto3
    import tempfile
    
    s3 = boto3.resource('s3', region_name=region)
    bucket = s3.Bucket(bucket)
    obj = bucket.Object(uploadedVolume)
    tmp = tempfile.NamedTemporaryFile()
    with open(tmp.name, 'wb') as f:
        obj.download_fileobj(f)
        stlMesh = stl.mesh.Mesh.from_file(tmp.name)
    
    volume, cog, inertia = stlMesh.get_mass_properties()