---
url: https://gudhub.com/docs/core-api/file-manager/
title: "File Manager\n                #"
description: "File Manager consists of methods that responsible for different functions: 1. getFile 2. getFiles 3. uploadFile 4. uploadFileFromString 5. uploadFileFromStringW"
lang: uk
updated: 2026-09-11T14:11:52.069Z
---

# File Manager [#](https://gudhub.com/docs/core-api/file-manager/#file-manager)

File Manager consists of methods that responsible for different functions:

1.  [getFile](#getfile)
    
2.  [getFiles](#getfiles)
    
3.  [uploadFile](#uploadfile)
    
4.  [uploadFileFromString](#uploadfilefromstring)
    
5.  [uploadFileFromStringWithSetValue](#uploadfilefromstringwithsetvalue)
    
6.  [isFileExists](#isfileexists)
    
7.  [updateFileFromString](#updatefilefromstring)
    
8.  [duplicateFile](#duplicatefile)
    
9.  [downloadFileFromString](#downloadfilefromstring)
    
10.  [deleteFile](#deletefile)
     

## getFile() [#](https://gudhub.com/docs/core-api/file-manager/#getfile)

This method is called to get file from the application. It takes application and file IDs as arguments.

Copy

```js
async gudhub.getFile(app_id, file_id)
```

Pass the method the application ID and the ID of the file you need.

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| app\_id | `number` | _application ID where we want to get the file_ |
| file\_id | `number` | _unique file ID_ |

Copy

```js
import GudHub from '@gudhub/core';

const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7T7GYfz67w2eu+dsidhfnc2364kjh322kjkcJIOHBJ";
let app_id = 23456;
let file_id = 92810029;

(async ()=>{
    const gudhub = await new GudHub(AUTHKEY);
    let gottenFile = await gudhub.getFile(app_id, file_id);
    console.log(gottenFile);
})();
```

It returns the file object:

Copy

```json
{
    "app_id": 26699,
    "extension": "jpg",
    "file_id": 885173,
    "file_name": "my_picture",
    "item_id": 2917052,
    "last_update": 0,
    "url": "https://gudhub.com/userdata/26699/885173.jpg",
}
```

## getFiles() [#](https://gudhub.com/docs/core-api/file-manager/#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.

Copy

```js
async gudhub.getFiles(app_id, file_id)
```

Current method accepts two arguments:

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| app\_id | `number` | _application ID where we want to get the file_ |
| filesId | `array` | _array of application\`s file IDs_ |

Copy

```js
import GudHub from '@gudhub/core';

const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7T7GYfz67w2eu+dsidhfnc2364kjh322kjkcJIOHBJ";
let app_id = 23456;
let filesId = ["2343", "2354"];

(async ()=>{
    const gudhub = await new GudHub(AUTHKEY);
    let gottenFiles = await gudhub.getFiles(app_id, filesId);
    console.log(gottenFiles);
})();
```

It returns an array of file objects:

Copy

```json
[{
    "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",
}]
```

## uploadFile() [#](https://gudhub.com/docs/core-api/file-manager/#uploadfile)

The current method expectedly allows to upload files. It is used only to transfer files to the form.

Copy

```js
async gudhub.uploadFile(fileData, app_id, item_id)
```

It accepts data of the file, application and item IDs of the destination location.

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| fileData | `object` | _contains form data of the file_ |
| app\_id | `number` | _contains ID of the destination application where the file will be upload_ |
| item\_id | `number` | _contains ID of the destination item where the file will be loaded_ |

Copy

```js
import GudHub from '@gudhub/core';

const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7T7GYfz67w2eu+dsidhfnc2365k";
let fileData = {
    lastModified: 1662377594650,
    lastModifiedDate: Mon Sep 05 2022 14:33:14 GMT+0300,
    name: "_72192176_thewolfofwallstreet001.jpg",
    size: 33503,
    type: "image/jpeg",
    webkitRelativePath: ""
};
let app_id = 23445;
let item_id = 1234343;

(async ()=>{
    const gudhub = new GudHub(AUTHKEY);
    let uploadedFile = await gudhub.uploadFile(fileData, app_id, item_id);
    console.log(uploadedFile);
})();
```

The method returns an object of the uploaded file.

Copy

```json
{
    "app_id": 28877,
    "extension": "jpg",
    "file_id": 953393,
    "file_name": "alignment_just",
    "item_id": 3118314,
    "last_update": 0,
    "url": "https://gudhub.com/userdata/28877/953393.jpg"
}
```

## uploadFileFromString() [#](https://gudhub.com/docs/core-api/file-manager/#uploadfilefromstring)

This is the method that allows to upload different files in base64 format to the application. It accepts object with seven properties:

Copy

```js
async gudhub.uploadFileFromString(fileObject)
```

As mentioned above, the method has only one argument.

| Name | Type | Description |
| :-- | :-- | :-- |
| fileObject | `object` | _object that contains all data of the file_ |

Copy

```js
import GudHub from '@gudhub/core';

const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7T7GYfz67w2eu+dsidhfnc2365k";
let fileObject = {
    "format":"html",
    "source":"test",
    "file_name":"document",
    "extension":"html",
    "app_id":"28818",
    "item_id":"3103065",
    "element_id":"679784"
}

(async ()=>{
    const gudhub = await new GudHub(AUTHKEY);
    let uploadedFile = await gudhub.uploadFileFromString(fileObject);
    let uploadedFile = await gudhub.uploadFileFromString({ "format":"html", "source":"test", "file_name":"document", "extension":"html", "app_id":"28818", "item_id":"3103065", "element_id":"679784"});
    console.log(uploadedFile);
})();
```

In response it returns object like this:

Copy

```json
{
    "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 [#](https://gudhub.com/docs/core-api/file-manager/#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:

Copy

```json
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAKCAYAAACNMs+9AAAABmJLR0QA/wD/AP+gvaeTAGJWNkMEJADEIBEcbwjyEQXSFECYII=
```

The part that is passed to source:

Copy

```json
iVBORw0KGgoAAAANSUhEUgAKCAYAAACNMs+9AAAABmJLR0QA/wD/AP+gvaeTAGJWNkMEJADEIBEcbwjyEQXSFECYII=
```

## uploadFileFromStringWithSetValue() [#](https://gudhub.com/docs/core-api/file-manager/#uploadfilefromstringwithsetvalue)

This method works the same way as [uploadFileFromString](#uploadfilefromstring), but additionally saves the `file_id` of the uploaded file as the value of the field defined by `element_id` in the passed `fileObject`.

Copy

```js
async gudhub.uploadFileFromStringWithSetValue(fileObject)
```

Just like `uploadFileFromString`, it accepts a single argument.

| Name | Type | Description |
| :-- | :-- | :-- |
| fileObject | `object` | _object that contains all data of the file_ |

Copy

```js
import GudHub from '@gudhub/core';

const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7T7GYfz67w2eu+dsidhfnc2365k";
let fileObject = {
    "format":"html",
    "source":"test",
    "file_name":"document",
    "extension":"html",
    "app_id":"28818",
    "item_id":"3103065",
    "element_id":"679784"
}

(async ()=>{
    const gudhub = await new GudHub(AUTHKEY);
    let uploadedFile = await gudhub.uploadFileFromStringWithSetValue(fileObject);
    console.log(uploadedFile);
})();
```

In response it returns the uploaded file object, the same as `uploadFileFromString` does:

Copy

```json
{
    "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
}
```

After the file is uploaded, the field with ID equal to `element_id` on item `item_id` in application `app_id` will have its value set to the uploaded file's `file_id` (`929765` in the example above).

## isFileExists() [#](https://gudhub.com/docs/core-api/file-manager/#isfileexists)

The current method allows you to check the existence of a certain file. It accepts two arguments that determine the file itself and its location. Namely, they allow you to find a file in the [File List](https://gudhub.com/docs/understanding-gudhub/application/file-list/).

Copy

```js
async gudhub.fileManager.isFileExists(app_id, file_id)
```

This method transfers the application and file IDs

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| app\_id | `number` | _contains the application ID of the file, which is checked_ |
| file\_id | `number` | _contains ID of the file that is checked_ |

Copy

```js
import GudHub from '@gudhub/core';

const AUTHKEY =  "NWfWIMActkcc2Z3p4uJ8jvKh/aF...";
let app_id = 23457;
let file_id = 33409209;

(async ()=>{
    const gudhub = await new GudHub(AUTHKEY);
    let isFileExists = await gudhub.fileManager.isFileExists(app_id, file_id);
    console.log(isFileExists);
})();
```

After checking if the file exists, the method returns _true_, if not - _false_.

Copy

```json
true
```

## updateFileFromString() [#](https://gudhub.com/docs/core-api/file-manager/#updatefilefromstring)

The current method is created to update the data or name of the certain file.

Copy

```js
async gudhub.updateFileFromString(data, file_id, file_name, extension, format)
```

It takes as arguments the file name, ID and data, its extension and format.

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| data | `string` | _contains new data of the file that will be updated_ |
| file\_id | `string` | _contains ID of the file that will be updated_ |
| file\_name | `string` | _transmits the updated name of the file that will be updated_ |
| extension | `string` | _transmits extension of the file that will be updated_ |
| format | `string` | _transmits format of the file that will be updated_ |

Copy

```js
import GudHub from '@gudhub/core';

const AUTHKEY =  "NWfWIMActkcc2Z3p4uJ8jvKh/aF...";
let data = "Hello World!";
let file_id = "232435";
let file_name = "Document";
let extension = "html";
let format = "html";

(async ()=>{
    const gudhub = await new GudHub(AUTHKEY);
    let updatedFile = await gudhub.updateFileFromString(data, file_id, file_name, extension, format);
    console.log(updatedFile);
})();
```

In response, the method will return a file list object with the updated file data.

Copy

```json
{
    "app_id": 29867,
    "extension": "html",
    "file_id": 962605,
    "file_name": "document_new",
    "item_id": 3206586,
    "last_update": 1663581687912,
    "url": "https://gudhub.com/userdata/29867/962605.html"
}
```

## duplicateFile() [#](https://gudhub.com/docs/core-api/file-manager/#duplicatefile)

The current method is called to create the copy of the file. It is only used on the server of the GudHub. Called when the user installs some application using [_Install_ element](https://gudhub.com/docs/gh-elements/install-element/).

Copy

```js
async gudhub.duplicateFile(files)
```

The single argument of the current method transmits an array with all updated data of the certain files.

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| files | `array` | _contains objects which consists of source of the file, namely the file ID, and IDs that determine the location where the file will be duplicated_ |

Copy

```js
import GudHub from '@gudhub/core';

const AUTHKEY =  "NWfWIMActkcc2Z3p4uJ8jvKh/aF...";
let files = [{
    source: 23455,
    destination: {
        app_id: 54683,
        item_id: 5323232,
        element_id: 123333
    }
},{
    source: 23456,
    destination: {
        app_id: 74788,
        item_id: 9434432,
        element_id: 436682
    }
}];

(async ()=>{
    const gudhub = new GudHub(AUTHKEY);
    let duplicatedFiles = await gudhub.duplicateFile(files);
    console.log(duplicatedFiles);
})();
```

In response, the method will return an array with updated files data objects.

Copy

```json
[{
    "app_id": 54683,
    "extension": "html",
    "file_id": 962605,
    "file_name": "document_new",
    "item_id": 5323232,
    "last_update": 1663581687912,
    "url": "https://gudhub.com/userdata/54683/962605.html"
},{
    "app_id": 74788,
    "extension": "html",
    "file_id": 962612,
    "file_name": "document_new",
    "item_id": 9434432,
    "last_update": 1663581687912,
    "url": "https://gudhub.com/userdata/74788/962612.html"
}]
```

## downloadFileFromString() [#](https://gudhub.com/docs/core-api/file-manager/#downloadfilefromstring)

As the name suggests, this method allows you to download a file from the file list of a specific application.

Copy

```js
async gudhub.downloadFileFromString(app_id,file_id)
```

This method takes two IDs as arguments.

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| app\_id | `number` | _contains ID of the application where the file is located_ |
| item\_id | `number` | _contains ID of the item where the file is located_ |

Copy

```js
import GudHub from '@gudhub/core';

const AUTHKEY =  "NWfWIMActkcc2Z3p4uJ8jvKh/aF...";
let app_id = 29523;
let file_id = 954407;

(async ()=>{
    const gudhub = await new GudHub(AUTHKEY);
    let downloadedFile = await gudhub.downloadFileFromString(app_id,file_id);
    console.log(downloadedFile);
})();
```

In response, we will receive the data of the uploaded file.

Copy

```json
{
    "data": "PK\u0003\u0004\u0014\u0000\u0006\u0000\b\u0000\u0",
    "file": { 
        "app_id": 29867,
        "extension": "docx",
        "file_id": 962585,
        "file_name": "document",
        "item_id": 3207532,
        "last_update": 0,
        "url": "https://gudhub.com/userdata/29867/962585.docx"
    },
    "type": "file"
}
```

## deleteFile() [#](https://gudhub.com/docs/core-api/file-manager/#deletefile)

Due to this method files can be deleted from the application. It takes application and file IDs as arguments.

Copy

```js
async gudhub.deleteFile(app_id, file_id)
```

Two arguments are passed to the method:

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| app\_id | `number` | _application ID where we want to get the file_ |
| file\_id | `number` | _unique file ID_ |

Copy

```js
import GudHub from '@gudhub/core';

const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7T7GYfz67w2eu+dsidhfnc2365k";
let app_id = 23456;
let file_id = 92810029;

(async ()=>{
    const gudhub = await new GudHub(AUTHKEY);
    let deletedFile = await gudhub.deleteFile(app_id, file_id);
    console.log(deletedFile);
})();
```

The object of the deleted item will be returned in response:

Copy

```json
{
    "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",
}
```
