Excerpt |
---|
Giles provides REST endpoints to specific functionality such as uploading or retrieving images. The following sections describe all so far available endpoints, their parameters, and what they return. |
Add files to Giles
In theory, you can add any file type you want to Giles. However, only file types supported by Digilib or file types that Giles knows how to convert really make sense. Currently, Giles knows how to convert PDFs to images. Giles is globally configurable in regards to what image type it uses and what DPI when converting PDFs to images (default is tiff/600 dpi). Giles will create one image per PDF page and put all images together into one folder so that you can use Digilib's paginator feature. The original PDF is stored separately outside of Digilib's image folder.
You can add files to Giles by making a POST request to:
/rest/files/upload
You request should be made with a content-type header of:
multipart/form-data
Giles expects the following parameters:
accessToken: a github access token that is used to authenticate the uploading user
access (optional): access policy for uploaded files; possible values are PRIVATE or PUBLIC; default is PRIVATE.
document_type (optional): specifies if uploaded files are several pages of the same document (MULTI_PAGE) or if they should be uploaded as separate documents (SINGLE_PAGE); default is SINGLE_PAGE.
files: the files to be uploaded
v0.6 and newer
Status | ||||
---|---|---|---|---|
|
Giles will respond with an progress id and a url to check the progress of the upload:
Code Block | ||
---|---|---|
| ||
{
"id":"PROGQ3Fm2J",
"checkUrl":"http://your-giles-org.net/giles/rest/files/upload/PROGQ3Fm2J"
} |
You can now poll the url provided as 'checkUrl'. As long as the upload hasn't finished yet, you will get a 202 Accepted response with the following response body:
Code Block | ||
---|---|---|
| ||
{
"msg":"Upload in progress. Please check back later.",
"msgCode":"010"
} |
Once uploading has finished, you will retrieve the complete information:
...
language | js |
---|---|
title | Upload Image Sample Response from Giles |
...
...
Authentication
For all REST endpoints, a user has to send a valid API token (see for a description how to get a token) to authenticate. Some endpoints can be used without a token when requesting public files. Below descriptions indicate when an endpoint can be used without a token. In general, there are two ways to send a token: as request parameter or as Authorization header (this is the recommended way).
When sending a token in the header, add the following header field:
Code Block |
---|
Authorization: token your-api-token |
When sending a token as request parameter, add the following to your url:
Code Block |
---|
accessToken=your-api-token |
Add files to Giles
Status | ||||
---|---|---|---|---|
|
In theory, you can add any file type you want to Giles. However, only file types supported by Digilib or file types that Giles knows how to convert really make sense. Currently, Giles knows how to convert PDFs to images. Giles is globally configurable in regards to what image type it uses and what DPI when converting PDFs to images (default is tiff/600 dpi). Giles will create one image per PDF page and put all images together into one folder so that you can use Digilib's paginator feature. The original PDF is stored separately outside of Digilib's image folder.
You can add files to Giles by making a POST request to:
/rest/files/upload
You request should be made with a content-type header of:
multipart/form-data
Giles expects the following parameters:
accessToken: an API token that is used to authenticate the uploading user (if possible use the Authorization header instead of this parameter)
access (optional): access policy for uploaded files; possible values are PRIVATE or PUBLIC; default is PRIVATE.
document_type (optional): specifies if uploaded files are several pages of the same document (MULTI_PAGE) or if they should be uploaded as separate documents (SINGLE_PAGE); default is SINGLE_PAGE.
files: the files to be uploaded
A valid request would look something like this:
Code Block |
---|
POST /giles/rest/files/upload HTTP/1.1
Host: giles-host
Authorization: token your-giles-token
Cache-Control: no-cache
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="files"; filename="test.png"
Content-Type: image/png
[content of file]
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="files"; filename="test.pdf"
Content-Type: application/pdf
[content of file] |
v0.6 and newer
Giles will respond with an progress id and a url to check the progress of the upload:
Code Block | ||
---|---|---|
| ||
{ "id":"PROGQ3Fm2J", "checkUrl":"http://your-giles-hostorg.net/giles/rest/files/FILE466tghupload/contentPROGQ3Fm2J", "path" : "username/UPxx456/DOC123edf/uploadedFile.pdf", "content-type" : "application/pdf", "size" : 3852180 }, "extractedText" : { } |
You can now poll the url provided as 'checkUrl'. As long as the upload hasn't finished yet, you will get a 202 Accepted response with the following response body:
Code Block | ||
---|---|---|
| ||
{
"msg":"Upload in progress. Please check back later.",
"msgCode":"010"
} |
Once uploading has finished, you will retrieve the complete information:
Code Block | ||||
---|---|---|---|---|
| ||||
[ { "documentId" : "DOC123edf", "uploadId" : "UPxx456", "uploadedDate" : "2016-09-20T14:03:00.152Z", "access" : "PRIVATE", "uploadedFile" : { "filename" : "uploadedFile.pdf.txt", "id" : "FILE123cvbFILE466tgh", "url" : "http://your-giles-host.net/giles/rest/files/FILE123cvbFILE466tgh/content", "path" : "username/UPxx456/DOC123edf/uploadedFile.pdf.txt", "content-type" : "textapplication/plainpdf", "size" : 397733852180 }, "pages" : [ { "nr" : 0, "imageextractedText" : { "filename" : "uploadedFile.pdf.0.tifftxt", "id" : "FILEYUI678FILE123cvb", "url" : "http://your-giles-host.net/giles/rest/digilib?fn=username%FILEYUI678%2FDOC123edf0%2FuploadedFile.pdf.0.tiff", /files/FILE123cvb/content", "path" : "username/UPxx456/DOC123edf/uploadedFile.pdf.0.tifftxt", "content-type" : "imagetext/tiffplain", "size" : 39773 }, "sizepages" : [ { 2032405 "nr" : }0, "textimage" : { "filename" : "uploadedFile.pdf.0.tiff.txt", "id" : "FILE789UIOFILEYUI678", "url" : "http://your-giles-host.net/giles/rest/files/FILE789UIO/contentdigilib?fn=username%FILEYUI678%2FDOC123edf0%2FuploadedFile.pdf.0.tiff", "path" : "username/UPxx456/DOC123edf/uploadedFile.pdf.0.tiff.txt", "content-type" : "textimage/plaintiff", "size" : 46582032405 }, }, { "nr" : 1, "image "text" : { "filename" : "uploadedFile.pdf.10.tiff.txt", "id" : "FILE045tyhGFILE789UIO", "url" : "http://your-giles-host.net/giles/rest/digilib?fn=username%2FFILE045tyhG%2FDOC123edf0%2FuploadedFile.pdf.1.tiff/files/FILE789UIO/content", "path" : "username/UPxx456/DOC123edf/uploadedFile.pdf.10.tiff.txt", "content-type" : "imagetext/tiffplain", "size" : 4658 2512354 } }, { "textnr" : {1, "image" : { "filename" : "uploadedFile.pdf.1.tiff.txt", "id" : "FILEMDSPfeVmFILE045tyhG", "url" : "http://your-giles-host.net/giles/rest/files/FILEMDSPfeVm/contentdigilib?fn=username%2FFILE045tyhG%2FDOC123edf0%2FuploadedFile.pdf.1.tiff", "path" : "username/UPxx456/DOC123edf/uploadedFile.pdf.1.tiff.txt", "content-type" : "textimage/plaintiff", "size" : 57992512354 }, "text" : } |
Uploads expire after 24 hours or after a server restart. If you request an expired upload or an upload that doesn't exist you will get a 404 response with the following response body:
Code Block |
---|
{{ "errorCodefilename" : "404uploadedFile.pdf.1.tiff.txt", "errorMsgid" : "FILEMDSPfeVm"Upload, does not exist." } |
v0.5 and older
Status | ||||
---|---|---|---|---|
|
For each uploaded file, Giles responds with either "success": 0
(upload was successful), or "success": 1
(upload failed).
Code Block | ||||
---|---|---|---|---|
| ||||
[ { "documentId" : "DOCnbxbFU", "uploadId" : "UP50N1AV", "uploadedDate" : "2016-07-26T21:38:34.398Z", "access" : "PRIVATE", "files" : [ { "filename" : "IMG_2836.jpeg", "path" : "http://diging-dev.asu.edu:8081/giles-review/rest/digilib?fn=jdamerow/UP50N1AV/FILEz7JQFu/IMG_2836.jpeg", "content-type" : "image/jpeg", "size" : 120830, "success" : 0, "id" : "FILE2FGTtG" }, { "url" : "http://your-giles-host.net/giles/rest/files/FILEMDSPfeVm/content", "path" : "username/UPxx456/DOC123edf/uploadedFile.pdf.1.tiff.txt", "content-type" : "text/plain", "size" : 5799 } } |
Uploads expire after 24 hours or after a server restart. If you request an expired upload or an upload that doesn't exist you will get a 404 response with the following response body:
Code Block |
---|
{
"errorCode" : "404",
"errorMsg" : "Upload does not exist."
} |
v0.5 and older
For each uploaded file, Giles responds with either "success": 0
(upload was successful), or "success": 1
(upload failed).
Code Block | ||||
---|---|---|---|---|
| ||||
[ { "documentId" : "DOCnbxbFU", "uploadId" : "UP50N1AV", "uploadedDate" : "2016-07-26T21:38:34.398Z", "access" : "PRIVATE", "files" : [ { "filename" : "IMG_0306.jpgyour-file.jpeg", "path" : "http://diging-dev.asu.edu:8081your.host/giles-review/rest/digilib?fn=jdamerowyouruser/UP50N1AV/FILETAW3KI/IMG_0306.jpgFILEz7JQFu/your-file.jpeg", "content-type" : "image/jpeg", "size" : 270769120830, "success" : 0, "id" : "FILE23rtGFILE2FGTtG" }, { ] } ] |
Get image from Digilib
Status | ||||
---|---|---|---|---|
|
You can get images from Digilib through Giles by making a GET request to:
/rest/digilib
Giles expects the following parameters:
- accessToken: a github access token that is used to authenticate the uploading user
- fn: path to image in digilib
- dw or dh: you need at least one size parameter, either width (dw) or height (dh) or both
- any other digilib parameter (optional)
...
"filename" : "your-file-2.jpg",
"path" : "http://your.host/giles/rest/digilib?fn=youruser/UP50N1AV/FILETAW3KI/your-file-2.jpg",
"content-type" : "image/jpeg",
"size" : 270769,
"success" : 0,
"id" : "FILE23rtG"
} ]
} ] |
Get image from Digilib
Status | ||||
---|---|---|---|---|
|
You can get
...
images from Digilib
...
through Giles by making a GET request to:
/rest/digilib/public
Giles expects the following parameters:
- accessToken: an API token that is used to authenticate the uploading user (if possible use the Authorization header instead of this parameter)
- fn: path to image in digilib
- dw or or dh: you need at least one size parameter, either width (dw) or height (dh) or both
- any other digilib parameter (optional)
If the requested image is set to public, Giles will return the image from Digilib. Otherwise, you will receive an http status 403 Forbidden.
...
Get public image from Digilib
Status | ||||
---|---|---|---|---|
|
You can get information about an upload public images from Digilib without a GitHub access token by making a GET request to:
/rest/files/upload/{uploadId}
...
digilib/public
Giles expects the following parameters:
- accessToken: a github access token that is used to authenticate the uploading user
A user has only access to upload he initiated himself.
...
language | js |
---|---|
title | Upload Info Sample Response from Giles |
...
- fn: path to image in digilib
- dw or dh: you need at least one size parameter, either width (dw) or height (dh) or both
- any other digilib parameter (optional)
If the requested image is set to public, Giles will return the image from Digilib. Otherwise, you will receive an http status 403 Forbidden.
Get info about upload
Status | ||||
---|---|---|---|---|
|
You can get information about an upload by making a GET request to:
/rest/files/upload/{uploadId}
where {uploadId}
refers to an id of a previous upload.
Giles expects the following parameters:
- accessToken: an API token that is used to authenticate the uploading user (if possible use the Authorization header instead of this parameter)
A user has only access to upload he initiated himself.
Code Block | ||||
---|---|---|---|---|
| ||||
[ "documentId" : "DOCOhcqLGMXL8dC",
"uploadId" : "UPMDG2ddX4bDKk",
"uploadedDate" : "2016-10-04T17:40:15.254Z",
"access" : "PUBLIC",
"uploadedFile" : {
"filename" : "your-file.pdf",
"id" : "FILE0fPS2iO6Ev7g",
"url" : "https://your.host/giles/rest/files/FILE0fPS2iO6Ev7g/content",
"path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf",
"content-type" : "application/pdf",
"size" : 1453836
},
"extractedText" : {
"filename" : "your-file.pdf.txt",
"id" : "FILEjXRK3MKDjcqx",
"url" : "https://your.host/giles/rest/files/FILEjXRK3MKDjcqx/content",
"path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf.txt",
"content-type" : "text/plain",
"size" : 84313
},
"pages" : [ {
"nr" : 0,
"image" : {
"filename" : "your-file.pdf.0.tiff",
"id" : "FILEgwyK2KjEiniN",
"url" : "https://your.host/giles/rest/digilib?fn=youruser%2FUPMDG2ddX4bDKk%2FDOCOhcqLGMXL8dC%2Fyour-file.pdf.0.tiff",
"path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf.0.tiff",
"content-type" : "image/tiff",
"size" : 1938832
},
"text" : {
"filename" : "your-file.pdf.0.txt",
"id" : "FILEu3zp4FHaNBEz",
"url" : "https://your.host/giles/rest/files/FILEu3zp4FHaNBEz/content",
"path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf.0.txt",
"content-type" : "text/plain",
"size" : 3461
}
}, {
"nr" : 1,
"image" : {
"filename" : "your-file.pdf.1.tiff",
"id" : "FILE1vgFj8feXHtG",
"url" : "https://your.host/giles/rest/digilib?fn=username%2FUPMDG2ddX4bDKk%2FDOCOhcqLGMXL8dC%2Fyour-file.pdf.1.tiff",
"path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf.1.tiff",
"content-type" : "image/tiff",
"size" : 1938382
},
"text" : {
"filename" : "your-file.pdf.1.txt",
"id" : "FILER0t8JQ1WuU94",
"url" : "https://your.host/giles/rest/files/FILER0t8JQ1WuU94/content",
"path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf.1.txt",
"content-type" : "text/plain",
"size" : 3930
}
}, {
"nr" : 2,
"image" : {
"filename" : "your-file.2.tiff",
"id" : "FILEzQaVarnXZy52",
"url" : "https://your.host/giles/rest/digilib?fn=youruser%2FUPMDG2ddX4bDKk%2FDOCOhcqLGMXL8dC%2Fyour-file.pdf.2.tiff",
"path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf.2.tiff",
"content-type" : "image/tiff",
"size" : 1809905
},
"text" : {
"filename" : "your-file.pdf.2.txt",
"id" : "FILEFlTXtknorFua",
"url" : "https://your.host/giles/rest/files/FILEFlTXtknorFua/content",
"path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf.2.txt",
"content-type" : "text/plain",
"size" : 3563
}
} ]
} ] |
Get info about document
Status | ||||
---|---|---|---|---|
|
Status | ||||
---|---|---|---|---|
|
You can get information about a document by making a GET request to:
/rest/documents/{documentId}
where {documentId}
is the id of the upload you are requesting information about.
A response looks similar to this:
Code Block |
---|
{ "documentId" : "DOCOhcqLGMXL8dC", "uploadId" : "UPMDG2ddX4bDKk", "uploadedDate" : "2016-10-04T17:40:15.254Z", "access" : "PUBLIC", "uploadedFile" : { "filename" : "your-file.pdf", "id" : "FILE0fPS2iO6Ev7g", "url" : "https://your.host/giles/rest/files/FILE0fPS2iO6Ev7g/content", "path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf", "content-type" : "application/pdf", "size" : 1453836 }, "extractedText" : { "filename" : "your-file.pdf.txt", "id" : "FILEjXRK3MKDjcqx", "url" : "https://your.host/giles/rest/files/FILEjXRK3MKDjcqx/content", "path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf.txt", "content-type" : "text/plain", "size" : 84313 }, "pages" : [ { "nr" : 0, "image" : { "filename" : "your-file.pdf.0.tiff", "id" : "FILEgwyK2KjEiniN", "url" : "https://your.host/giles/rest/digilib?fn=youruser%2FUPMDG2ddX4bDKk%2FDOCOhcqLGMXL8dC%2Fyour-file.pdf.0.tiff", "path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf.0.tiff", "content-type" : "image/tiff", "size" : 1938832 }, "text" : { "filename" : "your-file.pdf.0.txt", "id" : "FILEu3zp4FHaNBEz", "url" : "https://your.host/giles/rest/files/FILEu3zp4FHaNBEz/content", "path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf.0.txt", "content-type" : "text/plain", "size" : 3461 } }, { "nr" : 1, "image" : { "filename" : "your-file.pdf.1.tiff", "id" : "FILE1vgFj8feXHtG", "url" : "https://your.host/giles/rest/digilib?fn=youruser%2FUPMDG2ddX4bDKk%2FDOCOhcqLGMXL8dC%2Fyour-file.pdf.1.tiff", "path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf.1.tiff", "content-type" : "image/tiff", "size" : 1938382 }, "text" : { "filename" : "your-file.pdf.1.txt", "id" : "FILER0t8JQ1WuU94", "url" : "https://your.host/giles/rest/files/FILER0t8JQ1WuU94/content", "path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf.1.txt", "content-type" : "text/plain", "size" : 3930 } }, { "nr" : 2, "image" : { "filename" : "your-file.pdf.2.tiff", "id" : "FILEzQaVarnXZy52", "url" : "https://your.host/giles/rest/digilib?fn=youruser%2FUPMDG2ddX4bDKk%2FDOCOhcqLGMXL8dC%2Fyour-file.pdf.2.tiff", "path" : "youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/your-file.pdf.2.tiff", "content-type" : "image/tiff", "size" : 1809905 }, "text" : { "filename" : "your-file.pdf.2.txt", "id" : "FILEFlTXtknorFua", "url" : "https://your.host/giles/rest/files/FILEFlTXtknorFua/content", "path" : "http:youruser/UPMDG2ddX4bDKk/DOCOhcqLGMXL8dC/digingyour-devfile.asu.edu:8081/giles-review/rest/digilib?fn=jdamerow/UPR8QVBL/FILExedxqn/IMG_2836.jpeg",pdf.2.txt", "content-type" : "imagetext/jpegplain", "size" : 120830, "id" : "FILE23rtG"3563 } ] } ] |
Get full image from Giles
Status | ||||
---|---|---|---|---|
|
Status | ||||
---|---|---|---|---|
|
You can get the original version of a file that you have uploaded through Giles by making a GET request to:
...
Giles expects the following parameters:
- accessToken: a github access an API token that is used to authenticate the uploading user (if possible use the Authorization header instead of this parameter)
Note: when requesting information about an upload, or after uploading a file, the path property of the JSON response will point here for PDF files.
...