QuickBlox Documentation

QuickBlox provides powerful Chat API and SDK to add real-time messaging and video calls to your web and mobile apps. Learn how to integrate QuickBlox across multiple platforms and devices. Check out our detailed guides to make integration easy and fast.

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.

Before you begin

  1. Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.
  2. Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
  3. Configure QuickBlox SDK for your app. Check out our Setup page for more details.
  4. Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.

Upload file

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

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 i) {
        // i - upload progress in percents
    }
}).performAsync(new QBEntityCallback<QBFile>() {
    @Override
    public void onSuccess(QBFile qbFile, Bundle bundle) {
        // File uploaded successfully
    }

    @Override
    public void onError(QBResponseException e) {
        // Handle error
    }
});
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(i: Int) {
        // i - upload progress in percents
    }
}).performAsync(object : QBEntityCallback<QBFile> {
    override fun onSuccess(qbFile: QBFile?, bundle: Bundle?) { 
        // File uploaded successfully
    }

    override fun onError(e: QBResponseException?) { 
        // Handle error
    }
})

Parameters

Description

file

File in the local storage.

publicAccess

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

tags

Comma-separated string with tags.

progressCallback

(optional) Callback to receive upload progress.

Update file

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

File newFile = new File("pathname");
Integer qbFileID = qbFile.getId();
String tags = "dev, admin, birthday";

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

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

    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val newFile: File = File("pathname")
val qbFileID: Int = qbFile.id
val tags: String = "dev, admin, birthday"
        
QBContent.updateFileTask(newFile, qbFileID, tags, object : QBProgressCallback {
    override fun onProgressUpdate(i: Int) {
                
    }
}).performAsync(object : QBEntityCallback<QBFile> {
    override fun onSuccess(qbFile: QBFile?, bundle: Bundle?) {
                
    }

    override fun onError(e: QBResponseException?) {
                
    }
})

Retrieve files

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

//For single QBFile
QBContent.getFile(qbFile).performAsync(new QBEntityCallback<QBFile>() {
    @Override
    public void onSuccess(QBFile qbFile, Bundle bundle) {
                
    }

    @Override
    public void onError(QBResponseException e) {

    }
});
        
// 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> qbFiles, Bundle bundle) {
                
    }

    @Override
    public void onError(QBResponseException e) {

    }
});
//For single QBFile
QBContent.getFile(qbFile).performAsync(object : QBEntityCallback<QBFile> {
    override fun onSuccess(qbFile: QBFile?, bundle: Bundle?) {
                
    }

    override fun onError(e: 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(qbFiles: ArrayList<QBFile>?, bundle: Bundle?) {
                
    }

    override fun onError(e: QBResponseException?) {
                
    }
})

Download file by UID

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

String fileUID = qbFile.getUid();
        
QBContent.downloadFile(fileUID).performAsync(new QBEntityCallback<InputStream>() {
    @Override
    public void onSuccess(InputStream inputStream, Bundle bundle) {
                
    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val fileUID: String = qbFile.uid
        
QBContent.downloadFile(fileUID).performAsync(object : QBEntityCallback<InputStream> {
    override fun onSuccess(inputStream: InputStream?, bundle: Bundle?) {
                
    }

    override fun onError(e: QBResponseException?) {
                
    }
})

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.

String publicUrl = QBFile.getPublicUrlForUID(fileUID);
val publicUrl = QBFile.getPublicUrlForUID(fileUID)

Get private URL

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

String privateUrl = QBFile.getPrivateUrlForUID(fileUid);
val privateUrl = QBFile.getPrivateUrlForUID(fileUid)

Updated 3 months ago



Content


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

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.