File tree 1 file changed +12
-0
lines changed
1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -112,13 +112,25 @@ engine = create_engine(
112
112
Base.metadata.create_all(engine)
113
113
114
114
with Session(engine) as session, open (" ./example.txt" , " rb" ) as local_file:
115
+ # from an opened local file
115
116
session.add(Attachment(name = " attachment1" , content = local_file))
117
+
118
+ # from bytes
116
119
session.add(Attachment(name = " attachment2" , content = b " Hello world" ))
120
+
121
+ # from string
117
122
session.add(Attachment(name = " attachment3" , content = " Hello world" ))
123
+
124
+ # from a File object with custom filename and content_type
118
125
file = File(content = " Hello World" , filename = " hello.txt" , content_type = " text/plain" )
119
126
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
+
120
131
session.commit()
121
132
133
+
122
134
```
123
135
124
136
## Related projects and inspirations
You can’t perform that action at this time.
0 commit comments