File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -112,13 +112,25 @@ engine = create_engine(
112112Base.metadata.create_all(engine)
113113
114114with Session(engine) as session, open (" ./example.txt" , " rb" ) as local_file:
115+ # from an opened local file
115116 session.add(Attachment(name = " attachment1" , content = local_file))
117+
118+ # from bytes
116119 session.add(Attachment(name = " attachment2" , content = b " Hello world" ))
120+
121+ # from string
117122 session.add(Attachment(name = " attachment3" , content = " Hello world" ))
123+
124+ # from a File object with custom filename and content_type
118125 file = File(content = " Hello World" , filename = " hello.txt" , content_type = " text/plain" )
119126 session.add(Attachment(name = " attachment4" , content = file ))
127+
128+ # from a File object specifying a content path
129+ session.add(Attachment(name = " attachment5" , content = File(content_path = " ./example.txt" )))
130+
120131 session.commit()
121132
133+
122134```
123135
124136## Related projects and inspirations
You can’t perform that action at this time.
0 commit comments