|
1 |
| -# File Attachment Datatype |
| 1 | +# External Data |
2 | 2 |
|
3 |
| -## Configuration & usage |
| 3 | +## File Attachment Datatype |
4 | 4 |
|
5 |
| -<!-- Since https://github.com/datajoint/datajoint-python/issues/480 --> |
| 5 | +### Configuration & Usage |
6 | 6 |
|
7 |
| -The `attach` attribute type allows users to `attach` files into DataJoint |
| 7 | +Corresponding to issue |
| 8 | +[#480](https://github.com/datajoint/datajoint-python/issues/480), |
| 9 | +the `attach` attribute type allows users to `attach` files into DataJoint |
8 | 10 | schemas as DataJoint-managed files. This is in contrast to traditional `blobs`
|
9 | 11 | which are encodings of programming language data structures such as arrays.
|
10 | 12 |
|
11 | 13 | The functionality is modeled after email attachments, where users `attach`
|
12 |
| -a file along with a message, and message recipients have access to a |
| 14 | +a file along with a message and message recipients have access to a |
13 | 15 | copy of that file upon retrieval of the message.
|
14 | 16 |
|
15 | 17 | For DataJoint `attach` attributes, DataJoint will copy the input
|
16 |
| -file into a DataJoint store, hashing the file contents and tracking |
| 18 | +file into a DataJoint store, hash the file contents, and track |
17 | 19 | the input file name. Subsequent `fetch` operations will transfer a
|
18 |
| -copy of the file to the local directory of the python process and |
| 20 | +copy of the file to the local directory of the Python process and |
19 | 21 | return a pointer to it's location for subsequent client usage. This
|
20 | 22 | allows arbitrary files to be `uploaded` or `attached` to a DataJoint
|
21 | 23 | schema for later use in processing. File integrity is preserved by
|
22 |
| -checksumming the data upon attachment and verifying the contents |
| 24 | +checksum comparison against the attachment data and verifying the contents |
23 | 25 | during retrieval.
|
24 | 26 |
|
25 | 27 | For example, given a `localattach` store:
|
26 | 28 |
|
27 |
| -```json |
| 29 | +```python |
28 | 30 | dj.config['stores'] = {
|
29 |
| - 'localattach': { |
30 |
| - 'protocol': 'file', |
31 |
| - 'location': '/data/attach', |
32 |
| - } |
| 31 | + 'localattach': { |
| 32 | + 'protocol': 'file', |
| 33 | + 'location': '/data/attach' |
| 34 | + } |
33 | 35 | }
|
34 | 36 | ```
|
35 | 37 |
|
36 |
| -A `ScanAttachment` table can be created:: |
| 38 | +A `ScanAttachment` table can be created: |
37 | 39 |
|
38 | 40 | ```python
|
39 | 41 | @schema
|
40 | 42 | class ScanAttachment(dj.Manual):
|
41 |
| - definition = """ |
42 |
| - -> Session |
43 |
| - --- |
44 |
| - scan_image: attach@localattach # attached image scans |
45 |
| - """ |
| 43 | + definition = """ |
| 44 | + -> Session |
| 45 | + --- |
| 46 | + scan_image: attach@localattach # attached image scans |
| 47 | + """ |
46 | 48 | ```
|
47 | 49 |
|
48 | 50 | Files can be added using an insert pointing to the source file:
|
49 | 51 |
|
50 | 52 | ```python
|
51 |
| -ScanAttachment.insert1((0, '/input/image0.tif')) |
| 53 | +>>> ScanAttachment.insert1((0, '/input/image0.tif')) |
52 | 54 | ```
|
53 | 55 |
|
54 |
| -And then retrieved to the current directory using fetch: |
| 56 | +And then retrieved to the current directory using `fetch`: |
55 | 57 |
|
56 | 58 | ```python
|
57 | 59 | >>> s0 = (ScanAttachment & {'session_id': 0}).fetch1()
|
|
0 commit comments