File tree 5 files changed +46
-1
lines changed
5 files changed +46
-1
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
Original file line number Diff line number Diff line change @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
4
4
The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
5
5
and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
6
6
7
+ ## [ 0.6.0] - 2023-10-07
8
+
9
+ ---
10
+
11
+ ### Added
12
+
13
+ * Add option to upload files by path in [ #87 ] ( https://github.com/jowilf/sqlalchemy-file/pull/87 )
14
+ by [ @adscib ] ( https://github.com/adscib )
15
+
7
16
## [ 0.5.0] - 2023-07-21
8
17
9
18
---
Original file line number Diff line number Diff line change @@ -111,11 +111,22 @@ engine = create_engine(
111
111
Base.metadata.create_all(engine)
112
112
113
113
with Session(engine) as session, open (" ./example.txt" , " rb" ) as local_file:
114
+ # from an opened local file
114
115
session.add(Attachment(name = " attachment1" , content = local_file))
116
+
117
+ # from bytes
115
118
session.add(Attachment(name = " attachment2" , content = b " Hello world" ))
119
+
120
+ # from string
116
121
session.add(Attachment(name = " attachment3" , content = " Hello world" ))
122
+
123
+ # from a File object with custom filename and content_type
117
124
file = File(content = " Hello World" , filename = " hello.txt" , content_type = " text/plain" )
118
125
session.add(Attachment(name = " attachment4" , content = file ))
126
+
127
+ # from a File object specifying a content path
128
+ session.add(Attachment(name = " attachment5" , content = File(content_path = " ./example.txt" )))
129
+
119
130
session.commit()
120
131
121
132
```
Original file line number Diff line number Diff line change @@ -31,9 +31,22 @@ class Attachment(Base):
31
31
Base .metadata .create_all (engine )
32
32
33
33
with Session (engine ) as session , open ("./example.txt" , "rb" ) as local_file :
34
+ # from an opened local file
34
35
session .add (Attachment (name = "attachment1" , content = local_file ))
36
+
37
+ # from bytes
35
38
session .add (Attachment (name = "attachment2" , content = b"Hello world" ))
39
+
40
+ # from string
36
41
session .add (Attachment (name = "attachment3" , content = "Hello world" ))
42
+
43
+ # from a File object with custom filename and content_type
37
44
file = File (content = "Hello World" , filename = "hello.txt" , content_type = "text/plain" )
38
45
session .add (Attachment (name = "attachment4" , content = file ))
46
+
47
+ # from a File object specifying a content path
48
+ session .add (
49
+ Attachment (name = "attachment5" , content = File (content_path = "./example.txt" ))
50
+ )
51
+
39
52
session .commit ()
Original file line number Diff line number Diff line change 1
- __version__ = "0.5 .0"
1
+ __version__ = "0.6 .0"
2
2
3
3
from .file import File as File # noqa
4
4
from .types import FileField as FileField # noqa
You can’t perform that action at this time.
0 commit comments