1
- # start create bucket
2
- client = MongoClient ("<connection string>" )
3
- db = client ["db" ]
4
- bucket = gridfs .GridFSBucket (db )
5
- # end create bucket
1
+ # start create bucket
2
+ client = MongoClient ("<connection string>" )
3
+ db = client ["db" ]
4
+ bucket = gridfs .GridFSBucket (db )
5
+ # end create bucket
6
6
7
- # start create custom bucket
8
- custom_bucket = gridfs .GridFSBucket (db , bucket_name = "myCustomBucket" )
9
- # end create custom bucket
7
+ # start create custom bucket
8
+ custom_bucket = gridfs .GridFSBucket (db , bucket_name = "myCustomBucket" )
9
+ # end create custom bucket
10
10
11
- # start upload files
12
- with bucket .open_upload_stream (
13
- "my_file" , chunk_size_bytes = 1048576 ,
14
- metadata = { "contentType" : "text/plain" } ) as grid_in :
15
- grid_in .write ("data to store" )
16
- # end upload files
11
+ # start upload files
12
+ with bucket .open_upload_stream (
13
+ "my_file" , chunk_size_bytes = 1048576 , metadata = { "contentType" : "text/plain" }
14
+ ) as grid_in :
15
+ grid_in .write ("data to store" )
16
+ # end upload files
17
17
18
- # start retrieve file info
19
- for file_doc in bucket .find ({}):
20
- print (file_doc )
21
- # end retrieve file info
18
+ # start retrieve file info
19
+ for file_doc in bucket .find ({}):
20
+ print (file_doc )
21
+ # end retrieve file info
22
22
23
- # start download files name
24
- file = bucket .open_download_stream_by_name ("my_file" )
25
- contents = file .read ()
26
- # end download files name
23
+ # start download files name
24
+ file = bucket .open_download_stream_by_name ("my_file" )
25
+ contents = file .read ()
26
+ # end download files name
27
27
28
- # start download files id
29
- file = bucket .open_download_stream (ObjectId (' 66b3c86e672a17b6c8a4a4a9' ))
30
- contents = file .read ()
31
- # end download files id
28
+ # start download files id
29
+ file = bucket .open_download_stream (ObjectId (" 66b3c86e672a17b6c8a4a4a9" ))
30
+ contents = file .read ()
31
+ # end download files id
32
32
33
- # start rename files
34
- bucket .rename (ObjectId (' 66b3c86e672a17b6c8a4a4a9' ), "new_file_name" )
35
- # end rename files
33
+ # start rename files
34
+ bucket .rename (ObjectId (" 66b3c86e672a17b6c8a4a4a9" ), "new_file_name" )
35
+ # end rename files
36
36
37
- # start delete files
38
- bucket .delete (ObjectId (' 66b3c86e672a17b6c8a4a4a9' ))
39
- # end delete files
37
+ # start delete files
38
+ bucket .delete (ObjectId (" 66b3c86e672a17b6c8a4a4a9" ))
39
+ # end delete files
0 commit comments