如何使用boto3从Amazon S3获取.stl文件? [英] How to get .stl file from Amazon S3 by using boto3?
本文介绍了如何使用boto3从Amazon S3获取.stl文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Django Web应用程序,并将其部署到了Elastic Beanstalk环境.我也有numpy-stl软件包.我试图从Amazon S3存储桶中获取一个.stl文件,并将此文件与stl包的功能一起使用,但是却遇到诸如'bytes'对象没有属性'get_mass_properties'
之类的错误.
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'
.
我的代码是;
s3 = boto3.client('s3')
obj = s3.get_object(Bucket=bucket_name, Key=key)
body = obj['Body'].read()
volume, cog, inertia = body.get_mass_properties()
如何获取.stl文件并使用它?
How can i get the .stl file and use it?
推荐答案
我已修复如下问题.
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()
这篇关于如何使用boto3从Amazon S3获取.stl文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文