I'm attempting to create a stream for the .docx file returned from the user upload. I tried using .seek(0)
, .read()
, and .stream()
but each returned an error. Is there something I am missing? The .docx is sucessfully returned as a <class 'werkzeug.datastructures.FileStorage'>
object but I'm having trouble making it into a stream for the aspose.words
module to read.
@app.route('/home', methods=['GET','POST'])
def home():
if request.method == 'POST':
document = request.files['document']
stream = io.FileIO(document.read())
doc = aw.Document(stream)
CodePudding user response:
You should use either io.BytesIO(document.read())
or io.BufferedReader(document)
instead of io.FileIO(document.read())
.
io.FileIO
expects file name as an input parameter.