> ## 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/android-setup) page for more details.
3. Create a user session to be able to use QuickBlox functionality. See [Authentication](/sdks/android-authentication) page to learn how to do it.

## Retrieve files

To retrieve the list of **own** files, you can use code below.

<Tabs>
  <Tab title="Java">
    ```Java theme={null}
    // for single QBFile
    QBContent.getFile(file).performAsync(new QBEntityCallback<QBFile>() {
        @Override
        public void onSuccess(QBFile file, Bundle bundle) {

        }

        @Override
        public void onError(QBResponseException exception) {

        }
    });

    // or you can get a list of QBFiles:
    QBPagedRequestBuilder requestBuilder = new QBPagedRequestBuilder();
    requestBuilder.setPage(1);
    requestBuilder.setPerPage(10);

    QBContent.getFiles(requestBuilder).performAsync(new QBEntityCallback<ArrayList<QBFile>>() {
        @Override
        public void onSuccess(ArrayList<QBFile> files, Bundle bundle) {

        }

        @Override
        public void onError(QBResponseException exception) {

        }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```Kotlin theme={null}
    // for single QBFile
    QBContent.getFile(file).performAsync(object : QBEntityCallback<QBFile> {
        override fun onSuccess(file: QBFile?, bundle: Bundle?) {

        }

        override fun onError(exception: QBResponseException?) {

        }
    })

    // or you can get a list of QBFiles:
    val requestBuilder = QBPagedRequestBuilder()
    requestBuilder.page = 1
    requestBuilder.perPage = 10

    QBContent.getFiles(requestBuilder).performAsync(object : QBEntityCallback<ArrayList<QBFile>> {
        override fun onSuccess(files: ArrayList<QBFile>?, bundle: Bundle?) {

        }

        override fun onError(exception: QBResponseException?) {

        }
    })
    ```
  </Tab>
</Tabs>

## Upload file

You can upload a file to the cloud storage using the following code snippet.

<Tabs>
  <Tab title="Java">
    ```Java theme={null}
    File file = new File("pathname");
    boolean publicAccess = false;
    String tags = "dev, admin, birthday";

    QBContent.uploadFileTask(file, publicAccess, tags, new QBProgressCallback() {
        @Override
        public void onProgressUpdate(int progress) {

        }
    }).performAsync(new QBEntityCallback<QBFile>() {
        @Override
        public void onSuccess(QBFile file, Bundle bundle) {

        }

        @Override
        public void onError(QBResponseException exception) {

        }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```Kotlin theme={null}
    val file: File = File("pathname")
    val publicAccess: Boolean = false
    val tags: String = "dev, admin, birthday"

    QBContent.uploadFileTask(file, publicAccess, tags, object : QBProgressCallback {
        override fun onProgressUpdate(progress: Int) {

        }
    }).performAsync(object : QBEntityCallback<QBFile> {
        override fun onSuccess(file: QBFile?, bundle: Bundle?) {

        }

        override fun onError(exception: QBResponseException?) {

        }
    })
    ```
  </Tab>
</Tabs>

| Argument         | Required | Description                                                                                           |
| ---------------- | -------- | ----------------------------------------------------------------------------------------------------- |
| file             | yes      | File in the local storage.                                                                            |
| publicAccess     | yes      | File visibility. If the file is **public** then it's possible to download it without a session token. |
| tags             | yes      | Comma-separated string with tags.                                                                     |
| progressCallback | no       | Callback to receive upload progress.                                                                  |

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

It's also possible to update the file's data without creating a new content record.

<Tabs>
  <Tab title="Java">
    ```Java theme={null}
    File newFile = new File("pathname");
    Integer fileId = file.getId();
    String tags = "dev, admin, birthday";

    QBContent.updateFileTask(newFile, fileId, tags, new QBProgressCallback() {
        @Override
        public void onProgressUpdate(int progress) {

        }
    }).performAsync(new QBEntityCallback<QBFile>() {
        @Override
        public void onSuccess(QBFile file, Bundle bundle) {

        }

        @Override
        public void onError(QBResponseException exception) {

        }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```Kotlin theme={null}
    val newFile: File = File("pathname")
    val qbFileID: Int = file.id
    val tags: String = "dev, admin, birthday"

    QBContent.updateFileTask(newFile, fileID, tags, object : QBProgressCallback {
        override fun onProgressUpdate(progress: Int) {

        }
    }).performAsync(object : QBEntityCallback<QBFile> {
        override fun onSuccess(file: QBFile?, bundle: Bundle?) {

        }

        override fun onError(exception: QBResponseException?) {

        }
    })
    ```
  </Tab>
</Tabs>

## Download file by UID

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

<Tabs>
  <Tab title="Java">
    ```Java theme={null}
    String fileUID = file.getUid();

    QBContent.downloadFile(fileUID).performAsync(new QBEntityCallback<InputStream>() {
        @Override
        public void onSuccess(InputStream inputStream, Bundle bundle) {

        }

        @Override
        public void onError(QBResponseException exception) {

        }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```Kotlin theme={null}
    val fileUID: String = file.uid

    QBContent.downloadFile(fileUID).performAsync(object : QBEntityCallback<InputStream> {
        override fun onSuccess(inputStream: InputStream?, bundle: Bundle?) {

        }

        override fun onError(exception: QBResponseException?) {

        }
    })
    ```
  </Tab>
</Tabs>

## Get file info

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

<Tabs>
  <Tab title="Java">
    ```Java theme={null}
    int fileId = 8192;

    QBContent.getFile(fileId).performAsync(new QBEntityCallback<QBFile>() {
        @Override
        public void onSuccess(QBFile file, Bundle bundle) {

        }

        @Override
        public void onError(QBResponseException exception) {

        }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```Kotlin theme={null}
    val fileId = 8192

    QBContent.getFile(fileId).performAsync(object : QBEntityCallback<QBFile> {
        override fun onSuccess(file: QBFile, bundle: Bundle) {

        }

        override fun onError(exception: QBResponseException?) {

        }
    })
    ```
  </Tab>
</Tabs>

| Argument | Required | Description     |
| -------- | -------- | --------------- |
| fileID   | yes      | ID of the file. |

## Get file URL

Except for downloading, you can also get the URL of each `QBFile`. 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.

<Tabs>
  <Tab title="Java">
    ```Java theme={null}
    String publicUrl = QBFile.getPublicUrlForUID(fileUid);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```Kotlin theme={null}
    val publicUrl = QBFile.getPublicUrlForUID(fileUid)
    ```
  </Tab>
</Tabs>

| Argument | Required | Description                                                                                |
| -------- | -------- | ------------------------------------------------------------------------------------------ |
| fileUID  | yes      | File unique identifier. You can take the fileUid from the file using the getFile() method. |

### Get private URL

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

<Tabs>
  <Tab title="Java">
    ```Java theme={null}
    String privateUrl = QBFile.getPrivateUrlForUID(fileUid);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```Kotlin theme={null}
    val privateUrl = QBFile.getPrivateUrlForUID(fileUid)
    ```
  </Tab>
</Tabs>

| Argument | Required | Description                                                                                |
| -------- | -------- | ------------------------------------------------------------------------------------------ |
| fileUid  | yes      | File unique identifier. You can take the fileUid from the file using the getFile() method. |

## Delete file

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

<Tabs>
  <Tab title="Java">
    ```Java theme={null}
    int fileId = 8192;
    QBContent.deleteFile(fileId).performAsync(new QBEntityCallback<Void>() {
        @Override
        public void onSuccess(Void aVoid, Bundle bundle) {

        }

        @Override
        public void onError(QBResponseException exception) {

        }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```Kotlin theme={null}
    val fileId = 8192
    QBContent.deleteFile(fileID).performAsync(object : QBEntityCallback<Void> {
        override fun onSuccess(aVoid: Void, bundle: Bundle) {

        }

        override fun onError(exception: QBResponseException?) {

        }
    })
    ```
  </Tab>
</Tabs>

| Argument | Required | Description     |
| -------- | -------- | --------------- |
| fileID   | yes      | ID of the file. |
