Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: XNATRestClient -> XnatDataClient. Add HTTPie example.

Depending on the tool you are using to PUT files to the server, you may need to add an inbody=true query string parameter to force XNAT to treat the contents of your HTTP message as the actual file rather then as multi-part form data.

XNAT REST Tools

The XNAT team has developed some simple java based tools which can be used as command prompt tools to access the REST API.

XNATRestClient

...

Tools

XnatDataClient

The XnatDataClient is built specifically to facilitate user interaction with the REST API from the command prompt. Uploading files with this tool should be straightforward. You use the -local variable to identify the Use the -l (or --local) flag to give the path to the local file you are uploading. You use the -remote variable to identify the location you are PUTinig the file to.

XNATRestClient
Code Block
languagebash
XnatDataClient -host http://central.xnat.org -u USERUSERNAME -p PASSPASSWORD -m PUT -remoter "http:/data/archive/projectscentral.xnat.org/data/PATH/TO/DESTINATION/files" -locall filename./file.txt

Curl

Most UNIX operating systems come pre-installed with 'Curl' which is a tool for transferring data to or from a server. Because XNAT Servers are secured, you will need to provide a username and password to access the api. If you use the -F tag, the file will be sent to the server as part of a multipart-form message (similar to a browser post).  Without the -F tag, curl would post the file as the body of the message and you would need to set the mime-type of your message for XNAT to process it correctly (or use the ?inbody=true parameter).  For convenience, the -F works effectively.

Code Block
languagebash
curl -u USERNAME:PASSWORD -X PUT "http://central.xnat.org/data/archivePATH/projectsTO/PATH TO DESTINATION" -F "filename.txtfile=@filename.txt"

For more information on using curl, please review its documentation (https://curl.haxx.se/docs/tooldocs.html).

HTTPie


This tool was written in python (using the requests library) to mimic the syntax of curl while being better "unix citizen" than curl in how it reads stdin and writes stdout.

Code Block
languagebash
http -a USERNAME:PASSWORD --form PUT http://central.xnat.org/data/PATH/TO/DESTINATION/files file=@filename.txt

See more about HTTPie at its home or by reading its documentation.

Compressed file upload

The REST API supports the upload of compressed files that can be extracted on the server after successful upload. There are a few caveats:

...