Downloading Files via XNAT REST API

For the purposes of this instruction we will assume a stored session with the following structure.

Project:TEST
  Subject:1
    Experiment:MR1
       Scan:1 (TYPE:T1)
          resource:DICOM
             file:1.dcm
             file:2.dcm
          resource:SNAPSHOTS
             file:snap.jpg
       Scan:2 (TYPE:T1)
          resource:DICOM
             file:1.dcm
             file:2.dcm
          resource:SNAPSHOTS
             file:snap.jpg
       Scan:3 (TYPE:T2)
          resource:DICOM
             file:1.dcm
             file:2.dcm
          resource:SNAPSHOTS
             file:snap.jpg
       Scan:4 (TYPE:T2)
          resource:DICOM
             file:1.dcm
             file:2.dcm
          resource:SNAPSHOTS
             file:snap.jpg
 
       Reconstruction:RECON1  TYPE:T1
          resource:1
             file:something.img
             file:something.hdr
       Assessment:ASSESS1
          out resource: TEST
             file:something.img
             file:something.hdr
 

Within the scan, reconstruction, assessment, and resource levels of the URIs, you can use a few special tools to assist in the downloading of data, multiple IDs can be seperated by commas. Types can be substituted for scan IDs and reconstruction IDs.

Scan data

How do I download a single scan's DICOM data?

You can download the files for a single scan using the relevant scan ID.

/data/archive/projects/TEST/subjects/1/experiments/MR1/scans/1/resources/DICOM/files

This will return a list of the DICOM files for scan 1.

Do I have to download the files one by one?

No. You can use the query string parameter format=zip to return the actual files in a compressed archive instead of returning the list of files.

/data/archive/projects/TEST/subjects/1/experiments/MR1/scans/1/resources/DICOM/files?format=zip

How can I download all of the files for the scan (DICOM and SNAPSHOTS)?

You can download all of the files for the scan by leaving off the resource description.

/data/archive/projects/TEST/subjects/1/experiments/MR1/scans/1/files?format=zip

How can I download files for multiple scans?

If you know the relevant scan IDs, you can include multiple scan IDs in the URI seperated by a comma.

/data/archive/projects/TEST/subjects/1/experiments/MR1/scans/1,2/files?format=zip

How can I download all of the scans for the session?

You can also use the ALL keyword at the scan identification level.


/data/archive/projects/TEST/subjects/1/experiments/MR1/scans/ALL/files?format=zip

How can I download all of the T1 scans for the session?

You can substitute the scan TYPE in the uri at the scan identification level.

/data/archive/projects/TEST/subjects/1/experiments/MR1/scans/T1/files?format=zip

You can also provide a comma delimited list of scan types.

/data/archive/projects/TEST/subjects/1/experiments/MR1/scans/T1,T2/files?format=zip

Reconstruction Data

Similar to Scan data access you can use the ALL keyword, comma-seperated lists of scan IDs, and reconstruction TYPEs in your URIs for downloading data.

The template for Reconstruction file access is:

/data/archive/projects/{PROJECT_ID}/subjects/{SUBJECT_ID}/experiments/{EXPT_ID}/reconstructions/{RECON ID or TYPE or ALL}/resources/{TYPE or ID}/files

Assessment Data

Similar to scan and reconstruction access, you can use the ALL keyword and comma-seperated lists of assessor IDs in your URIs. However, instead of allowing the substitution of the TYPE attribute, you can use the XSI:TYPE of the data you are interested in.


/data/archive/projects/{PROJECT_ID}/subjects/{SUBJECT_ID}/experiments/{EXPT_ID}/assessors/{ASSESS ID or xsi:type or ALL}/resources/{TYPE or ID}/files

$label.name