Download saved file
Downloads a file saved on the SAYMON server.
Request
Response
If you append ?json
to the end of the request, the system will return the JSON representation of the file. The name
field contains the file name of the downloaded image, the data
field contains the base64-encoded image data.
If you don’t specify the json
parameter, the system will return the file as binary.
Example of JSON representation
{
"name": "image-file.png",
"data": "data:image/png;base64,iVBORw..."
}
Examples
Download file
This example downloads a file with the specified ID.
Request
This request returns the binary file, so you should output the result directly to the file to avoid corrupting it.
-
Bash
-
JavaScript
-
NodeJS
-
Python
login=<...>
password=<...>
saymon_hostname=<...>
file_id=<...>
url=https://$saymon_hostname/node/api/files/$file_id
curl -X GET $url -u $login:$password -o image.png
let login = <...>
let password = <...>
let saymonHostname = <...>
let fileId = <...>
let path = "/node/api/files/" + fileId;
let auth = "Basic " + btoa(login + ":" + password);
let headers = new Headers();
headers.append("Authorization", auth);
let requestOptions = {
method: "GET",
headers: headers
};
fetch(saymonHostname + path, requestOptions)
.then(response => response.blob())
.then(blob => {
var file = window.URL.createObjectURL(blob);
window.location.assign(file);
})
.catch(error => console.log("error", error));
const http = require("http");
const fs = require('fs');
let login = <...>
let password = <...>
let saymonHostname = <...>
let fileId = <...>
let path = "/node/api/files/" + fileId;
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");
let options = {
"method": "GET",
"hostname": saymonHostname,
"headers": {
"Authorization": auth
},
"path": path
};
let req = http.request(options, function (res) {
let chunks = [];
....
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
let body = Buffer.concat(chunks);
console.log(body.toString());
....
fs.writeFile('image.png', body.toString(), function (err) {
if (err) return console.log(err);
console.log('Saved image.png');
});
});
res.on("error", function (error) {
console.error(error);
}); });
req.end();
import requests
import urllib.request
login = <...>
password = <...>
saymon_hostname = <...>
file_id = <...>
url = "https://" + saymon_hostname + "/node/api/files/66ba293f8244cc1c4b35ffb8"
urllib.request.urlretrieve("http://"+ saymon_hostname +"/node/api/files/" + file_id + "?auth-token=" + api_token, 'image.png')
Get file as JSON
This example returns a file with the specified ID as a JSON object containing its name and the base64-encoded file data.
Request
-
Bash
-
JavaScript
-
NodeJS
-
Python
login=<...>
password=<...>
saymon_hostname=<...>
file_id=<...>
url=https://$saymon_hostname/node/api/files/$file_id?json
curl -X GET $url -u $login:$password
let login = <...>
let password = <...>
let saymonHostname = <...>
let fileId = <...>
let path = "/node/api/files/" + fileId + "?json";
let auth = "Basic " + btoa(login + ":" + password);
let headers = new Headers();
headers.append("Authorization", auth);
let requestOptions = {
method: "GET",
headers: headers
};
fetch(saymonHostname + path, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log("error", error));
const http = require("http");
let login = <...>
let password = <...>
let saymonHostname = <...>
let fileId = <...>
let path = "/node/api/files/" + fileId + "?json";
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");
let options = {
"method": "GET",
"hostname": saymonHostname,
"headers": {
"Authorization": auth
},
"path": path
};
let req = http.request(options, function (res) {
let chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
let body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
req.end();
import requests
login = <...>
password = <...>
saymon_hostname = <...>
file_id = <...>
url = "https://" + saymon_hostname + "/node/api/files/" + file_id + "?json"
response = requests.request("GET", url, auth=(login, password))
print(response.text)