The following code uses Stingray's RESTful API to a file to the extra directory. The code is written in Python. This program adds the file 'validserialnumbers' to the extra directory and if the file already exists it will be overwrite it. If this is not the desired behavior, code can be added to to check for the existence of the file as was done in the addpool example.
This code was tested with Python 2.7.3 and version 1.1.0 of the requests library.
Run the Python script as follows:
Since this is a file and not a configuration resource, JSON will not be used and the MIME type will be "application/octet-stream". Another difference when dealing with files is how Stingray handles adding a file that already exists. If the file already exists, Stingray will overwrite the it and return a HTTP status code of 204. If the file doesn't already exist, the HTTP status code will be a 201.