如何使用pythonocc-core StlAPI_Writer将数据写入Amazon S3?

问题描述

我有一个Django应用程序,它已部署到Amazon Elastic Beanstalk(在64位Amazon Linux 2 / 3.0.3上运行的Python 3.7)。我正在尝试将.stp文件转换为.stl文件,并使用pythonocc-core库将其保存到Amazon S3 Bucket。当我尝试保存到本地时,convert2stl函数起作用,但是将.stl保存到S3存储桶时,该函数不起作用。

这是我的convert2stl函数

import boto3
import tempfile
from OCC.Core.STEPControl import STEPControl_Reader
from OCC.Core.StlAPI import StlAPI_Writer
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh

@staticmethod
def convert2stl(bucket,file):
    input_file  = 'media/' + file
    if '.stp' in file:
        file_name = file.replace('.stp','')
    else:
        file_name = file
    output_file = bucket + 'media/' + file_name + '.stl'
    s3 = boto3.resource('s3',region_name='eu-central-1')
    bucket = s3.Bucket('bucket')
    obj = bucket.Object(input_file)
    step_reader = STEPControl_Reader()
    tmp = tempfile.NamedTemporaryFile()
    with open(tmp.name,'wb') as f:
        obj.download_fileobj(f)
        step_reader.ReadFile(tmp.name)
        step_reader.TransferRoot()
        myshape = step_reader.Shape()
        print("File readed")
    # Export to STL
    stl_writer = StlAPI_Writer()
    stl_writer.SetASCIIMode(True)
    mesh = BRepMesh_IncrementalMesh(myshape,0.9)
    mesh.Perform()
    stl_writer.Write(myshape,output_file)
    print("Written")
    return output_file

如您所见,我将存储段url作为输出文件提供,但是它不起作用。而且它不会给出任何错误。如何将该文件写入S3存储桶?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)