Skip to content

Commit ab7745f

Browse files
committed
Update README.md
1 parent 5ae55ce commit ab7745f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,25 @@ engine = create_engine(
112112
Base.metadata.create_all(engine)
113113

114114
with 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

0 commit comments

Comments
 (0)