I have Flask frontend project and I use flask-sqlalchemy with pymssql database.
There is existing .net tool that saves files to varbinary(max)
column in sql server db and it can download files too just fine.
Now I need flask view to output those files from varbinary(max)
column.
I currently have the following code
// in model
content = db.Column(VARBINARY())
// in view
query = models.File.query
f = query.filter(models.File.request_id == request_id).first_or_404()
response = Response(f.content, content_type='application/pdf')
response.headers["Content-Disposition"] = "attachment;filename={0}".format(file_name)
return response
Files are mostly pdfs and sample pdf is working just fine, but normal pdf files are corrupted, and I know they are ok in db, as .net client download them just fine.
So how to tweak f.content
encoding so user would be able to open mentioned pdfs ?
Interesting that type(f.content) is returning 'str' so I belive flask-sqlalchemy internally converts array of bytes to string.
OK, I figured that out.
Code I have was correct, and it outputs file in a right format.
Problem was with freedts driver, it has limit of 64512 bytes in freedts.conf
text size = 64512
Changing it to something more sane fixes the error.