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 our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.
Before you begin
- 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.
- Configure QuickBlox SDK for your app. Check out our Setup page for more details.
- Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.
Retrieve files
To retrieve the list of own files, you can use code below.
// 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) {
}
});
// 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?) {
}
})
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 progress) {
}
}).performAsync(new QBEntityCallback<QBFile>() {
@Override
public void onSuccess(QBFile file, Bundle bundle) {
}
@Override
public void onError(QBResponseException exception) {
}
});
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?) {
}
})
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 |
Update file
It's also possible to update the file's data without creating a new content record.
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) {
}
});
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?) {
}
})
Download file by UID
If the file is public then it's possible to download it without a session token.
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) {
}
});
val fileUID: String = file.uid
QBContent.downloadFile(fileUID).performAsync(object : QBEntityCallback<InputStream> {
override fun onSuccess(inputStream: InputStream?, bundle: Bundle?) {
}
override fun onError(exception: QBResponseException?) {
}
})
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.
int fileId = 8192;
QBContent.getFile(fileId).performAsync(new QBEntityCallback<QBFile>() {
@Override
public void onSuccess(QBFile file, Bundle bundle) {
}
@Override
public void onError(QBResponseException exception) {
}
});
val fileId = 8192
QBContent.getFile(fileId).performAsync(object : QBEntityCallback<QBFile> {
override fun onSuccess(file: QBFile, bundle: Bundle) {
}
override fun onError(exception: QBResponseException?) {
}
})
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.
String publicUrl = QBFile.getPublicUrlForUID(fileUid);
val publicUrl = QBFile.getPublicUrlForUID(fileUid)
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.
String privateUrl = QBFile.getPrivateUrlForUID(fileUid);
val privateUrl = QBFile.getPrivateUrlForUID(fileUid)
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.
int fileId = 8192;
QBContent.deleteFile(fileId).performAsync(new QBEntityCallback<Void>() {
@Override
public void onSuccess(Void aVoid, Bundle bundle) {
}
@Override
public void onError(QBResponseException exception) {
}
});
val fileId = 8192
QBContent.deleteFile(fileID).performAsync(object : QBEntityCallback<Void> {
override fun onSuccess(aVoid: Void, bundle: Bundle) {
}
override fun onError(exception: QBResponseException?) {
}
})
Argument | Required | Description |
---|---|---|
fileID | yes | ID of the file. |
Updated about 3 years ago