trying to upload stl model with python

Discussion in 'Shapeways API' started by wzesk, Jul 12, 2011.

  1. wzesk
    wzesk New Member
    Below is my attempt. Does anyone have an example of how to format a .stl into an array[byte]?

     def submit(self):
            if self.session_id:
                model = self.assembly.SWModel()
                model.title = "test"
                model.desc = "test"
                model.modeltype = "STL"
                model.file = (base64.b64encode(open("test.stl").read()))
                model.filename = "test"
                model.tags = "test"
                model.has_color = 0
                model.scale = 1.0
                model.markup = 1.0
                loaded = self.shapelink.submitModel(self.session_id,model,"", self.application_id)
                return loaded
    Last edited: Jul 12, 2011
  2. wzesk
    wzesk New Member
    got it working.

    Here is the solution I used :
    model.file = tuple(bytearray((open("test.stl").read()),"base64"))
  3. lancepickens
    lancepickens New Member
    you need to specify 'rb' in your open method to specify to treat the file as binary.