Some more information and samples of your code will help. You can use the html A element to enable a user to download a file from their browser. You have to link the "href" property of the A element as the contents of the dxf file.
Here is an example of how to do this with ezdxf information, based on Mozman's information above too:
# Export file as string data so it can be transfered to the browser html A element href:
# Create a string io object: An in-memory stream for text I/O
stream_obj = io.StringIO()
# write the doc (ie the dxf file) to the doc stream object
doc.write(stream_obj)
# get the stream object values which returns a string
dxf_text_string = stream_obj.getvalue()
# close stream object as required by good practice
stream_obj.close()
file_data = "data:text/csv;charset=utf-8," + dxf_text_string
and then assign the "file_data" to the href property. I use Dash - Plotly callbacks and can provide you with code on how to do it in that if you want.
Or you can also use the flask.send_file function in a flask routing. This requires the data to be in binary format.
# The following code is within a flask routing
# Create a BytesIO object
mem = io.BytesIO()
# Get the stringIO values as string, encode it to utf-8 and write it to the bytes object
# Create a string io object: An in-memory stream for text I/O
stream_obj = io.StringIO()
# write the doc (ie the dxf file) to the doc stream object
doc.write(stream_obj)
# The bytes object file type object is what is required for the flask.send_file method to work
mem.write(stream_obj.getvalue().encode('utf-8'))
mem.seek(0)
# Close StringIO object
stream_obj.close()
return flask.send_file(
mem,
mimetype='text/csv',
attachment_filename='drawing.dxf',
as_attachment=True,
cache_timeout=0
)
I can provide you with more information if you want but you may need to provide some of your code structure to see how youre encoding and passing the data around. Thanks JF