REST /repo

Rest repository allow to upload files to REST server. This files are given an unique id and are downloadable with this id.

Exemple

Send a file to REST server:

$ curl --request PUT --data-binary @foo.jpg http://192.168.0.10:40405/repo/put?filename=foo.jpg
{"status" : "OK", "code" : 0, "description" : "None", "repository" : [{"file" : "c624fd17-704c-4ed3-a905-12312c2bd29f.jpg"}]}

Here, your file will be accessible as http://192.168.0.10:40405/repo/get/c624fd17-704c-4ed3-a905-12312c2bd29f.jpg.

Why a repository ?

This repository exists for plugins that need to give a file (picture, sound) to user itnerfaces. For example, a vocal message or a text to speech audio file.

How can a plugin find repository ?

A plugin doesn’t know where is REST. So, it will have to read /etc/domogik/domogik.cfg file to get REST ip and port.

API

/repo/put?filename=foo.wav

This url is te be called with PUT method. filename value could be different of real filename, only the extension is important and will be kept. Complete filename is used in log files to keep a trace.

REST will answer a Json structure:

{"status" : "OK", "code" : 0, "description" : "None", "repository" : [{"file" : "c624fd17-704c-4ed3-a905-12312c2bd29f.jpg"}]}

file is the file id (file name on server and name to use with /repo/get to download file).

/repo/get/foo.wav

This url could be called with GET/OPTIONS or POST method. It will give you the file. In case of error, it will return you a typical REST Json error structure. For example:

{"status" : "ERROR", "code" : 999, "description" : "You must give a file name : ?filename=foo.txt"}

So, you should test mimetype of the data you get before using it ;)