Understanding files
The deviceWISE Cloud stores files
- associated with a specific thing, or
- associated with an organization (global).
Files identifiers are retrieved from the deviceWISE Cloud using the file.put command and the file.get command. The file is then uploaded to the deviceWISE Cloud using an HTTP POST command or retrieved from the deviceWISE Cloud using an HTTP GET command.
Tags are associated to files to help with filtering on the file display pages and have security tags associated with them to restrict access.
It is possible to restrict access to users and applications in the same organization or allow access by users and applications in other organizations (public).
Uploading files
Uploading a file to the deviceWISE Cloud is a two step process:
- Use
file.put
command to send the deviceWISE Cloud the file information and get a fileId in return. - Use HTTP POST to upload the file
to the deviceWISE Cloud using the fileId obtained
from the
file.put
command.
For example:
// file.put command is called:
{
"cmd": {
"command": "file.put",
"params": {
"fileName": "test_results.xls"
}
}
}
// file.put result:
{
"cmd": {
"success": true,
"params": {
"fileId": "50000000000000000000042"
}
}
}
// Upload the file to the deviceWISE Cloud via an HTTP POST in your programming environment. An example using curl is:
curl -x POST --data-binary @test_results.xls http://api.devicewise.com/file/50000000000000000000042
Retrieving files
Retrieving a file from the deviceWISE Cloud is a two step process:
- Use
file.get
command to send the deviceWISE Cloud the file information and get a fileId in return. - Use HTTP GET to retrieve the file
from the deviceWISE Cloud using the fileId obtained
from the
file.get
command.
For example:
// file.get command is called:
{
"cmd": {
"command": "file.get",
"params": {
"fileName": "test_results.xls",
"global": true
}
}
}
// file.get result:
{
"cmd": {
"success": true,
"params": {
"fileId": "50000000000000000000042",
"fileSize": 2824
}
}
}
// Download the file from the deviceWISE Cloud via an HTTP GET in your programming environment. An example using curl is:
curl -o test_results.xls http://api.devicewise.com/file/50000000000000000000042
In the above example, the api.devicewise.com URL is from the Developer page ( HTTPS or HTTP Endpoint without the /api )
Retrieving Private Files
A private file can be retrieved using one of the following URL structures.
1) This URL structure is for a file (not associated with a thing) and will cause a basic auth challenge. The username should be left blank, and the private token of the file should be used as the password.
https://<API_URL>/privfile/<ORG_KEY>/<FILE_NAME>
For example: https://api.devicewise.com/privfile/DEMO/private.txt
2) This URL structure is for a file that is associated with a thing and will cause a basic auth challenge. The username should be left blank, and the private token of the file should be used as the password.
https://<API_URL>/privfile/<ORG_KEY>/<THING_KEY>/<FILE_NAME>
For example: https://api.devicewise.com/privfile/DEMO/mythingkey/private.txt
3) These URL structures are for a file (not associated with a thing), and will not cause a basic auth challenge.
https://<API_URL>/privfile/<ORG_KEY>/<FILE_NAME>?t=<PRIVATE_TOKEN>
For example: https://api.devicewise.com/privfile/DEMO/private.txt?t=a23ce56gik78m14o
https://:<PRIVATE_TOKEN>@<API_URL>/privfile/<ORG_KEY>/<FILE_NAME>
For example: https://:a23ce56gik78m14o@api.devicewise.com/privfile/DEMO/private.txt
4) These URL structure are for a file associated with a thing, and will not cause a basic auth challenge.
https://<API_URL>/privfile/<ORG_KEY>/<THING_KEY>/<FILE_NAME>?t=<PRIVATE_TOKEN>
For example: https://api.devicewise.com/privfile/DEMO/mythingkey/private.txt?t=a23ce56gik78m14o
https://<API_URL>/privfile/<ORG_KEY>/<THING_KEY>/<FILE_NAME>?t=<PRIVATE_TOKEN>
For example: https://:a23ce56gik78m14o@api.devicewise.com/privfile/DEMO/mythingkey/private.txt
Variable descriptions
Variable |
Description |
---|---|
<API_URL> | The HTTP or HTTPS endpoint from the Developer page without the /api path. In the examples above, api.devicewise.com is shown. |
<FILE_NAME> | The name of the file to be acquired. In the examples above, private.txt is shown. |
<PRIVATE_TOKEN> | The 16 character string returned by the the file.put API command used to initiate the private file upload process. In the examples above, a23ce56gik78m14o is shown. |
<ORG_KEY> | The key of your organization. In the examples above, DEMO is shown. |
<THING_KEY> | The key of the thing that the file is related to (if the file is uploaded directly to a thing). In the examples above, mythingkey is shown. |