@@ -47,67 +47,53 @@ The request header's content type has to be set to `application/json`.
47
47
48
48
## Adding Resources with Image Files
49
49
50
- Certain resource classes can have attached image files. There are two ways to
51
- attach a file to a resource: Either by submitting directly the binaries of the file in a
52
- an HTTP Multipart request, or by indicating the location of the file. The two cases are referred to
53
- as non-GUI case and GUI case (see [ Sipi and Knora] ( ../../07-sipi/sipi-and-knora.md ) ).
54
-
55
- ### Including the binaries (non-GUI case)
56
-
57
- In order to include the binaries, a HTTP Multipart request has to be
58
- sent. One part contains the JSON (same format as described for
59
- [ Adding Resources Without Images Files] ( #adding-resources-without-a-digital-representation ) )
60
- and has to be named ` json ` . The other part contains the file's name, its binaries, and its mime type
61
- and has to be named ` file ` . The following example illustrates how to
62
- make this type of request using Python 3:
63
-
64
- ``` python
65
- # !/usr/bin/env python3
66
-
67
- import requests, json
68
-
69
- # a Python dictionary that will be turned into a JSON object
70
- resourceParams = {
71
- ' restype_id' : ' http://www.knora.org/ontology/test#testType' ,
72
- ' properties' : {
73
- ' http://www.knora.org/ontology/test#testtext' : [
74
- {' richtext_value' : {' utf8str' : " test" }}
75
- ],
76
- ' http://www.knora.org/ontology/test#testnumber' : [
77
- {' int_value' : 1 }
78
- ]
79
- },
80
- ' label' : " test resource" ,
81
- ' project_id' : ' http://rdfh.ch/projects/testproject'
82
- }
83
-
84
- # the name of the file to be submitted
85
- filename = " myimage.jpg"
50
+ The first step is to upload an image file to Sipi, using a
51
+ ` multipart/form-data ` request, where ` sipihost ` represents the host and
52
+ port on which Sipi is running:
86
53
87
- # a tuple containing the file's name, its binaries and its mimetype
88
- file = {' file' : (filename, open (filename, ' rb' ), " image/jpeg" )} # use name "file"
54
+ ```
55
+ HTTP POST to http://sipihost/upload?token=TOKEN
56
+ ```
89
57
90
- # do a POST request providing both the JSON and the binaries
91
- r = requests.post(" http://host/v1/resources" ,
92
- data = {' json' : json.dumps(resourceParams)}, # use name "json"
93
- files = file ,
94
- auth = (' user' , ' password' ))
58
+ The ` TOKEN ` is the ` sid ` returned by Knora in response to the
59
+ client's login request (see [ Authentication] ( authentication.md ) ).
60
+ The request must contain a body part providing the file as well as a parameter
61
+ ` filename ` , providing the file's original filename, which both Knora and Sipi will
62
+ store; these filenames can be descriptive and need not be unique.
63
+
64
+ Sipi will then convert the uploaded image file to JPEG 2000 format and store
65
+ it in a temporary location. If this is successful, it will return a JSON
66
+ response that looks something like this:
67
+
68
+ ``` json
69
+ {
70
+ "uploadedFiles" : [{
71
+ "originalFilename" : " manuscript-1234-page-1.tiff" ,
72
+ "internalFilename" : " 3UIsXH9bP0j-BV0D4sN51Xz.jp2" ,
73
+ "temporaryBaseIIIFUrl" : " http://sipihost/tmp"
74
+ }]
75
+ }
95
76
```
96
77
97
- Please note that the file has to be read in binary mode (by default it
98
- would be read in text mode).
78
+ This provides:
99
79
100
- ### Indicating the location of a file (GUI case)
80
+ - the ` originalFilename ` , which we submitted when uploading the file
81
+ - the unique ` internalFilename ` that Sipi has randomly generated for the file
82
+ - the ` temporaryBaseIIIFUrl ` , which we can use to construct a IIIF URL for
83
+ previewing the file
101
84
102
- This request works similarly to
103
- [ Adding Resources Without Image Files ] ( #adding-resources-without-a-digital-representation ) . The JSON format is described
104
- in the TypeScript interface ` createResourceWithRepresentationRequest ` in
105
- module ` createResourceFormats ` . The request header's content type has to
106
- set to ` application/json ` .
85
+ The client may now wish to get a thumbnail of the uploaded image, to allow
86
+ the user to confirm that the correct files have been uploaded. This can be done
87
+ by adding the filename and IIIF parameters to ` temporaryBaseIIIFUrl ` . For example, to get
88
+ a JPG thumbnail image whose width and height are at most 128 pixels wide, you would request
89
+ ` http://sipihost/tmp/3UIsXH9bP0j-BV0D4sN51Xz.jp2/full/!128,128/0/default.jpg ` .
107
90
108
- In addition to [ Adding Resources Without Image Files] ( #adding-resources-without-a-digital-representation ) , the
109
- (temporary) name of the file, its original name, and mime type have to
110
- be provided (see [ GUI Case] ( ../../07-sipi/sipi-and-knora.md#gui-case ) ).
91
+ The request to Knora works similarly to
92
+ [ Adding Resources Without Image Files] ( #adding-resources-without-image-files ) ,
93
+ with the addition of ` file ` , whose value is the ` internalFilename ` that Sipi returned.
94
+ See the TypeScript interface ` createResourceWithRepresentationRequest ` in
95
+ module ` createResourceFormats ` for details. The request header's content type must be
96
+ set to ` application/json ` .
111
97
112
98
## Response to a Resource Creation
113
99
@@ -122,7 +108,7 @@ The JSON format of the response is described in the TypeScript interface
122
108
## Changing a Resource's Label
123
109
124
110
A resource's label can be changed by making a PUT request to the path
125
- segments ` resources/label ` . The resource's Iri has to be provided in the
111
+ segments ` resources/label ` . The resource's IRI has to be provided in the
126
112
URL (as its last segment). The new label has to submitted as JSON in the
127
113
HTTP request's body.
128
114
@@ -150,18 +136,24 @@ Only system or project administrators may use the bulk import.
150
136
The procedure for using this feature is as follows
151
137
(see the [ example below] ( #bulk-import-example ) ).
152
138
153
- 1 . Make an HTTP GET request to Knora to [ get XML schemas] ( #1-get-xml-schemas ) describing
154
- the XML to be provided for the import.
155
- 2 . [ Generate an XML import document] ( #2-generate-xml-import-document ) representing the
156
- data to be imported, following the Knora import schemas that were generated in step 1.
157
- You will probably want to write a script to do this. Knora is not involved in this step.
158
- If you are also importing image files, this XML document needs to
159
- [ contain the filesystem paths] ( #bulk-import-with-image-files ) of those files.
160
- 3 . [ Validate your XML import document] ( #3-validate-xml-import-document ) , using an XML schema validator such as
161
- [ Apache Xerces] ( http://xerces.apache.org ) or [ Saxon] ( http://www.saxonica.com ) , or an
162
- XML development environment such as [ Oxygen] ( https://www.oxygenxml.com ) . This will
163
- help ensure that the data you submit to Knora is correct. Knora is not involved in this step.
164
- 4 . [ Submit the XML import document to Knora] ( #4-submit-xml-import-document-to-knora ) .
139
+ 1 . Make an HTTP GET request to Knora to [ get XML schemas] ( #1-get-xml-schemas ) describing
140
+ the XML to be provided for the import.
141
+
142
+ 2 . If you are importing image files, [ upload files to Sipi] ( #2-upload-files-to-sipi ) .
143
+
144
+ 3 . [ Generate an XML import document] ( #3-generate-xml-import-document ) representing the
145
+ data to be imported, following the Knora import schemas that were generated in step 1.
146
+ You will probably want to write a script to do this. Knora is not involved in this step.
147
+ If you are also importing image files, this XML document needs to
148
+ [ contain the filenames] ( #bulk-import-with-image-files ) that Sipi returned
149
+ for the files you uploaded in step 2.
150
+
151
+ 4 . [ Validate your XML import document] ( #4-validate-xml-import-document ) , using an XML schema validator such as
152
+ [ Apache Xerces] ( http://xerces.apache.org ) or [ Saxon] ( http://www.saxonica.com ) , or an
153
+ XML development environment such as [ Oxygen] ( https://www.oxygenxml.com ) . This will
154
+ help ensure that the data you submit to Knora is correct. Knora is not involved in this step.
155
+
156
+ 5 . [ Submit the XML import document to Knora] ( #5-submit-xml-import-document-to-knora ) .
165
157
166
158
In this procedure, the person responsible for generating the XML import
167
159
data need not be familiar with RDF or with the ontologies involved.
@@ -206,7 +198,12 @@ containing three files:
206
198
207
199
- ` knoraXmlImport.xsd ` : The standard Knora XML import schema, used by all XML imports.
208
200
209
- #### 2. Generate XML Import Document
201
+ #### 2. Upload Files to Sipi
202
+
203
+ See [ Upload Files to Sipi] ( ../api-v2/editing-values.md#upload-files-to-sipi ) in
204
+ the Knora API v2 documentation.
205
+
206
+ #### 3. Generate XML Import Document
210
207
211
208
We now convert our existing data to XML, probably by writing a custom
212
209
script. The resulting XML import document could look like this:
@@ -305,18 +302,6 @@ This illustrates several aspects of XML imports:
305
302
306
303
- The type of each value must be specified using the attribute
307
304
` knoraType ` .
308
-
309
- - If a property has ` knoraType="date_value" ` , the date value must have the following format:
310
-
311
- ```
312
- (GREGORIAN|JULIAN|ISLAMIC):\d{1,4}(-\d{1,2}(-\d{1,2})?)?( BC| AD| BCE| CE)?(:\d{1,4}(-\d{1,2}(-\d{1,2})?)?( BC| AD| BCE| CE)?)?
313
- ```
314
-
315
- E.g. an exact date like `GREGORIAN:2015-12-03` or a period like `GREGORIAN:2015-12-03:2015-12-04`.
316
- Dates may also have month or year precision, e.g. `ISLAMIC:1407-02` (the whole month of december) or `JULIAN:1330`
317
- (the whole year 1330). An optional ERA indicator term (`BCE`, `CE`, or `BC`, `AD`) can be added to the date, when no
318
- era is provided the default era `AD` will be considered. Era can be given as `GREGORIAN:1220 BC` or in range as
319
- `GREGORIAN:600 BC:480 BC`.
320
305
321
306
- A link to another resource described in the XML import is
322
307
represented as a child element of a property element, with
@@ -351,7 +336,7 @@ This illustrates several aspects of XML imports:
351
336
- A text value can have a ` lang ` attribute, whose value is an ISO 639-1
352
337
code specifying the language of the text.
353
338
354
- #### 3 . Validate XML Import Document
339
+ #### 4 . Validate XML Import Document
355
340
356
341
You can use an XML schema validator such as [ Apache Xerces] ( http://xerces.apache.org ) or
357
342
[ Saxon] ( http://saxon.sourceforge.net/ ) , or an XML development environment
@@ -364,7 +349,7 @@ For example, using Saxon:
364
349
java -cp ./saxon9ee.jar com.saxonica.Validate -xsd:p0801-biblio.xsd -s:data.xml
365
350
```
366
351
367
- #### 4 . Submit XML Import Document to Knora
352
+ #### 5 . Submit XML Import Document to Knora
368
353
369
354
To create these resources in Knora, make an HTTP post request with the XML import document
370
355
as the request body. The URL must specify the (URL-encoded) IRI of the project in which
@@ -421,8 +406,8 @@ contains the IRI of the target resource.
421
406
422
407
To attach an image file to a resource, we must provide the
423
408
element ` knoraXmlImport:file ` before the property elements. In this
424
- element, we must give the absolute filesystem path to the file that
425
- should be attached to the resource, along with its MIME type:
409
+ element, we must provide a ` filename ` attribute, containing the ` internalFilename `
410
+ that Sipi returned for the file in [ 2. Upload Files to Sipi ] ( #2-upload-files-to-sipi ) .
426
411
427
412
``` xml
428
413
<?xml version =" 1.0" encoding =" UTF-8" ?>
@@ -437,7 +422,7 @@ should be attached to the resource, along with its MIME type:
437
422
</incunabula : book >
438
423
<incunabula : page id =" test_page" >
439
424
<knoraXmlImport : label >a page with an image</knoraXmlImport : label >
440
- <knoraXmlImport : file path = " /usr/local/share/import-images/incunabula/12345.tiff " mimetype = " image/tiff " />
425
+ <knoraXmlImport : file filename = " 67SEfNU1wK2-CSf5abe2eh3.jp2 " />
441
426
<incunabula : origname knoraType =" richtext_value" >Chlaus</incunabula : origname >
442
427
<incunabula : pagenum knoraType =" richtext_value" >1a</incunabula : pagenum >
443
428
<incunabula : partOf >
@@ -448,6 +433,5 @@ should be attached to the resource, along with its MIME type:
448
433
</knoraXmlImport : resources >
449
434
```
450
435
451
- During the processing of the bulk import, Knora will
452
- communicate the location of file to Sipi, which will convert it to JPEG 2000
453
- for storage.
436
+ During the processing of the bulk import, Knora will ask Sipi for the rest of the
437
+ file's metadata, and store that metadata in a file value attached to the resource.
0 commit comments