def create_file(record, bucket, filename, stream):
obj = ObjectVersion.create(bucket, filename, stream=stream)<EOL>rb = RecordsBuckets(record_id=record.id, bucket_id=obj.bucket_id)<EOL>db.session.add(rb)<EOL>record.update(dict(<EOL>_files=[dict(<EOL>bucket=str(bucket.id),<EOL>key=filename,<EOL>size=obj.file.size,<EOL>checksum=str(obj.file.checksum),<EOL>version_id=str(obj.version_id),<EOL>), ]<EOL>))<EOL>record.commit()<EOL>db.session.commit()<EOL>
Create a file and add in record.