File Manager
File Manager consists of methods that responsible for all processes connected with files, namely for uploading, duplicating, receiving and deleting.
getFile
This method is called to get file from the application. It takes application and file IDs as arguments.
import GudHub from '@gudhub/core';
const gudhub = new GudHub(authkey);
gudhub.getFile(app_id, file_id);
Argument Name | Type | Description |
---|---|---|
app_id | number |
application ID where we want to get the file |
file_id | number |
unique file ID |
It returns the file object:
{
"app_id": 26699,
"extension": "jpg",
"file_id": 885173,
"file_name": "8skovoroda",
"item_id": 2917052,
"last_update": 0,
"url": "https://gudhub.com/userdata/26699/885173.jpg",
}
getFiles
This method is called for getting a list of files from current application. It takes application ID and array of file IDs as arguments.
import GudHub from '@gudhub/core';
const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7T7GYfz67w2eu+dsidhfnc2365kjh322kjkcJIOHBJ";
const gudhub = new GudHub(AUTHKEY);
let filesId = [{
file_id: "2343"
},
{
file_id: "2354"
}]
gudhub.getFiles(app_id, filesId);
Argument Name | Type | Description |
---|---|---|
app_id | number |
application ID where we want to get the file |
filesId | array |
array of application`s file IDs |
It returns an array of file objects:
[{
"app_id": 26699,
"extension": "jpg",
"file_id": 885173,
"file_name": "8skovoroda",
"item_id": 2917052,
"last_update": 234455567,
"url": "https://gudhub.com/userdata/26699/885173.jpg",
},
{
"app_id": 26709,
"extension": "png",
"file_id": 885384,
"file_name": "34",
"item_id": 2917121,
"last_update": 2244555677,
"url": "https://gudhub.com/userdata/26699/885173.jpg",
}]
uploadFileFromString
This is the method that allows to upload different files in base64 format to the application. It accepts seven arguments:
import GudHub from '@gudhub/core';
const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7T7GYfz67w2eu+dsidhfnc2365kjh322kjkcJIOHBJ";
const gudhub = new GudHub(AUTHKEY);
let source = "iVBORw0KGgoAAAANSUhEUgAKCAYAAACNMs+9AAAABmJLR0QA/wD/AP+gvaeTAGJWNkMEJADEIBEcbwjyEQXSFECYII=";
let extension = "jpg";
let format = "base64";
gudhub.uploadFileFromString(source, file_name, app_id, item_id, extension, format, element_id)
Name | Type | Description |
---|---|---|
source | string |
part of base64 file; details... |
file_name | string |
original file name |
app_id | number |
ID of application where the file will be uploaded |
item_id | number |
ID of item where the file will be uploaded |
extension | string |
extension of the source file |
format | string |
format of the source data |
element_id | number |
ID of element where the file will be uploaded |
In response it returns object like this:
{
"file_id": 929765,
"app_id": 26290,
"item_id": 3041132,
"file_name": "image",
"url": "https://gudhub.com/userdata/22390/323765.jpg",
"extension": "jpg",
"last_update": 0
}
source
As you already know, we pass base64 code of the file to source. Namely, in this method we use only signs after the comma.
Full Base64:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAKCAYAAACNMs+9AAAABmJLR0QA/wD/AP+gvaeTAGJWNkMEJADEIBEcbwjyEQXSFECYII=
The part that is passed to source:
iVBORw0KGgoAAAANSUhEUgAKCAYAAACNMs+9AAAABmJLR0QA/wD/AP+gvaeTAGJWNkMEJADEIBEcbwjyEQXSFECYII=
deleteFile
Due to this method files can be deleted from the application. It takes application and file IDs as arguments.
import GudHub from '@gudhub/core';
const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7T7GYfz67w2eu+dsidhfnc2365kjh322kjkcJIOHBJ";
const gudhub = new GudHub(AUTHKEY);
gudhub.deleteFile(app_id, file_id);
Argument Name | Type | Description |
---|---|---|
app_id | number |
application ID where we want to get the file |
file_id | number |
unique file ID |
The object of the deleted item will be returned in response:
{
"app_id": 26699,
"extension": "png",
"file_id": 885184,
"file_name": "34",
"item_id": 2917052,
"last_update": 0,
"url": "https://gudhub.com/userdata/26699/885173.jpg",
}