> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quickblox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Content

> Learn how to store and access files with QuickBlox file storage.

The content module allows storing rich chat attachments, app content, and settings without having to republish them. Using a web interface you or your clients can control and make instant changes to the apps.

Visit [Key Concepts](/docs/key-concepts) page to learn the most important QuickBlox concepts.

## Before you begin

1. Register a [QuickBlox account](https://admin.quickblox.com/signin). This is a matter of a few minutes and you will be able to use this account to build your apps.
2. Configure QuickBlox SDK for your app. Check out [Setup](/sdks/js-setup) page for more details.
3. Create a user session to be able to use QuickBlox functionality. See [Authentication](/sdks/js-authentication) page to learn how to do it.

## Retrieve files

Get a list of files for a current user using the code snippet below.

```JavaScript JavaScript theme={null}
// these parameters are optional
var params = {
  page: 1,
  per_page: 10
};

QB.content.list(params, function(error, data) {
  // ...
});

// equivalent of the above code
QB.content.list(function(error, data) {
  // ...
});
```

## Upload file

Upload a file to the cloud storage using the following code snippet.

```JavaScript JavaScript theme={null}
var input = document.querySelector("input[type=file]");
var file = input.files[0];

var params = {
  name: file.name,
  file: file,
  type: file.type,
  size: file.size,
  public: false // optional, "false" by default
};

QB.content.createAndUpload(params, function(error, result) {
  if (error) {
    console.log(error);
  } else {
    console.log(result);
    var uploadedFile = result;
    var uploadedFileId = result.uid;
  }
});
```

The maximum size of the uploaded file depends on the membership plan.

| Basic           | Startup | Growth | HIPAA | Enterprise |                                                                 |
| --------------- | ------- | ------ | ----- | ---------- | --------------------------------------------------------------- |
| File size limit | 10 Mb   | 25 Mb  | 50Mb  | 50Mb       | [Contact our sales team](https://quickblox.com/enterprise/#get) |

## Update file

You can update a file name using the `update()` method.

```JavaScript JavaScript theme={null}
var params = {
  id: 101,
  name: "GreatPlace", // new file name
};

QB.content.update(params, function(error, result) {
  if (error) {
    console.log(error);
  } else {
    console.log(result);
  }
});
```

Set the following fields of the `params`:

| Field | Required | Description     |
| ----- | -------- | --------------- |
| id    | yes      | ID of the file. |
| name  | yes      | File name.      |

## Download file by UID

If the file is public then it's possible to download it without a session token.

```JavaScript JavaScript theme={null}
QB.content.getFile('file uid', function (error, file) {
  // ...
})
```

## Get file info

Get information about a file by ID using the `getInfo()` method below. This method allows to load the file description model from the server, not the content of the file itself.

```JavaScript JavaScript theme={null}
var fileId = 1441441;
QB.content.getInfo(fileId, function(error, result) {
  // ...
});
```

| Argument   | Required | Description                                                                  |
| ---------- | -------- | ---------------------------------------------------------------------------- |
| fileId     | yes      | ID of the file.                                                              |
| function() | yes      | Specifies a callback function that accepts that accepts an error and result. |

## Get file URL

Except for downloading, you can also get URL of each file. There are two types of file URLs that can be obtained: private and public.

* **Public URL** allows anyone to access the file, no authorization token is needed.
* **Private URL** can be accessed only by QuickBlox user with a session token.

### Get public URL

To receive a public URL, use the code snippet below.

```JavaScript JavaScript theme={null}
var fileUID = 'file uid';

var fileUrl = QB.content.publicUrl(fileUID);
```

| Argument | Required | Description                                                                                                                         |
| -------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| fileUID  | yes      | File unique identifier. You can take the fileUID from the object received as a result of the createAndUpload() or getInfo() method. |

### Get private URL

To get a private URL of the uploaded file, use the following code snippet.

```JavaScript JavaScript theme={null}
var fileUID = 'file uid';

var fileUrl = QB.content.privateUrl(fileUID);
```

| Argument | Required | Description                                                                                                                         |
| -------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| fileUID  | yes      | File unique identifier. You can take the fileUID from the object received as a result of the createAndUpload() or getInfo() method. |

## Delete file

Delete a file by file ID using the `delete()` method below.

```JavaScript JavaScript theme={null}
var fileId = 1441441;
QB.content.delete(fileId, function(error, result) {
  // ...
});
```

| Argument   | Required | Description                                                                  |
| ---------- | -------- | ---------------------------------------------------------------------------- |
| fileId     | yes      | ID of the file.                                                              |
| function() | yes      | Specifies a callback function that accepts that accepts an error and result. |
